Java Program to access character of a string

To access character of a string in Java, use the charAt() method. The position is to be added as the parameter.

Let’s say we have the following string −

String str = "laptop";

Let’s find the character at the 4th position using charAt() method.


The following is the final example.


 Live Demo

public class Demo {
   public static void main(String[] args) {
      String str = "laptop";
      System.out.println("String: "+str);
      // finding character at 4th position
      System.out.println("Character at 4th position: "+str.charAt(3));


String: laptop
Character at 4th position: t

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 12-Sep-2023

30K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started