Java String charAt() Method


The String charAt() method is used to returns the character at a specified location.

 

The charAt() method is used to extract a single character from a string. The value should be non-negative and specify a location within the string.

 

The index number starts from zero and ends at n-1.

 

Syntax:

public char charAt(int index)  

Example:

public class Charatmethod{  
    public static void main(String args[]){  
        String s1="Welcome to OnlineTpoint"; 
        char ch=s1.charAt(8);//returns the char value of index number
		System.out.println(ch);  
    }
} 



OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.