Java Program to get a character located at the String's specified index

Java 8Object Oriented ProgrammingProgramming

Use the charAt() method in Java to get a character located at a specified index.

Let’s say the following is our string.

String str = "Laptop...";

Finding character at 3rd position.

str.charAt(2);

The following is the final example.

Example

 Live Demo

public class Demo {
    public static void main(String[] args) {
       String str = "Laptop...";
       System.out.println("String: "+str);
       System.out.println("Character at position 3 = " +str.charAt(2));
    }
}

Output

String: Laptop...
Character at position 3 = p
raja
Published on 12-Dec-2018 08:07:36
Advertisements