Java – Get First Character from String

To get first character from String in Java, use String.charAt() method. Call charAt() method on the string and pass zero 0 as argument. charAt(0) returns the first character from this string.

Java Program

public class Example {
	public static void main(String[] args) {
		String str = "abcdefgh";
		char firstChar = str.charAt(0);
		System.out.println("First Character of given string is : " + firstChar);
	}
}

Output

First Character of given string is : a

Conclusion

In this Java Tutorial, we learned how to get first character from Java String.