Answers for "grab the first letter of each string in an array java"

1

get first letter of string in array java

// Array of names
		String name [] = {"Clark", "Bruce", "Diana", "Barry"};
		
		// for each loop (to iterate everything inside the array)
		for (String names: name) {
			System.out.println(names.charAt(0));
		}

		/* Prints
        	C
            B
            D
            B
        */
Posted by: Guest on February-09-2022
0

how to return the first character in an array from a method java

public String firstElement(String[] array)
{
      if (array.length >= 1)
      {
      return array[0];
      }
      else {
          return "";
      }
}
Posted by: Guest on March-18-2020

Code answers related to "grab the first letter of each string in an array java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language