Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

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
        */
Comment

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 "";
      }
}
Comment

PREVIOUS NEXT
Code Example
Java :: find the unique element in a list java 
Java :: java class in dataweave 
Java :: Java Enabling Assertions 
Java :: springbootservletinitializer maven dependency 
Java :: java lamda 
Java :: interface in solidity 
Java :: java stream code to ignore null 
Java :: thread in java 
Java :: calling java static method in kotlin 
Java :: enhance for loop java 
Java :: binary tree level traversal 
Java :: set union java 
Java :: list of strings java 
Java :: JFrame change outline 
Java :: how to make jenkins pipeline choose specific java version 
Java :: java run jnlp 
Java :: resultset next method 
Java :: transparent border of jtextfield in java 
Java :: find the third largest number in an array 
Java :: java create array 
Java :: map.keyset in java 
Java :: sharedpreferences 
Java :: enhanced for loop arraylist 
Java :: qr code spring boot 
Java :: how to take binary input in java 
Java :: getter in java 
Java :: how to find lcm of two numbers java 
Java :: Java Expression statements 
Java :: generate hash in java 
Java :: java design patterns 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =