Java – Get Character at Specified Index from String

To get character at specified index from String, use String.charAt() method. Call charAt() method on the string and pass the index as argument. charAt() returns the character from this string at specified index.

Java Program

public class Example {
	public static void main(String[] args) {
		String str = "abcdefgh";
		int index = 3;
		char ch = str.charAt(index);
		System.out.println("Character at index " + index + " is : " + ch);
	}
}

Output

ADVERTISEMENT
Character at index 3 is : d

Conclusion

In this Java Tutorial, we learned how to get character at specified index from Java String.