Java-Extracting Character

Extracting Character

The charAt( ) method provides the character at the specified index position. The starting value of the index in the case of a string is zero. For example, in the following program, the character at position 3 in the string “hajsof” is ‘s’. Thus, the str1.charAt(3) method will return the character ‘s’.

Concat

You can concatenate two strings using concat( ). The concat( ) performs the same function as +.

Program

Program Source

public class Javaapp {

    public static void main(String[] args) {
        
        String str1 = new String("hajsof");
        char c = str1.charAt(3);
        System.out.println("char c = "+c);
        str1 = str1.concat("tutorial");
        System.out.println("str1 = "+str1); 
    }
}

Leave a Comment