In this section you will get detail about charAt() in java. This method comes in java.lang.String package. charAt() return the character at the given index within the string, index starting from 0. This method return the character at the specified index in the string.
charAt() method in java
In this section you will get detail about charAt() in java. This method comes in java.lang.String package. charAt() return the character at the given index within the string, index starting from 0. This method return the character at the specified index in the string.
Syntax:
public char charAt(int index)
index - index of the character to be returned.
Example: A program how to use charAt() method in java.
import java.lang.*; class Demo { public static void main(String args[]) { String s="welcome to rose india"; char pos =s.charAt(3); // return the character at position 3rd System.out.println("character at 3rd position is = "+pos); } }
Output : After compiling and executing the above program.