Char at position from string in java

Get char at position from string in java

The charAt method of the String class take an index and return the Character in that position.

The charAt method indexes start from 0 and will throw a java.lang.StringIndexOutOfBoundsException if the index is bigger than the size of the string

public class ChatAtMain {

    public static void main(String args[]) {
        String str = "yami code";
        char c = str.charAt(3);
        // Output: i
        System.out.println(c);
    }
}