Retrieve the indexed character from string in Java

package javabasics;

public class StringUsage 
{

	public static void main(String[] args) 
	{
		
		String S1 = "India is my country";
		String S2 = "USA is my country";		  
				  
		//Retrieve the 10th Indexed character from string S1
		System.out.println("Character at Index 10 Is : --- "+S1.charAt(10)+"\n");
		
		//Retrieve the 10th Indexed character from string S2
		System.out.println("Character at Index 10 Is : --- "+S2.charAt(10)+"\n");
		
		

	}

}

Output:

Character at Index 10 from String S1 is : --- y

Character at Index 10 from String S2 is : --- y

 

Leave a Reply

Your email address will not be published. Required fields are marked *