Extracting Character and Concatenation

Java-Extracting Character and Concatenation

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 example, the character at position 3 in the string “ABCDEFG” is ‘D’. Thus, the str1.charAt(3) method will return the character ‘D’. Example:

Extracting Character and Concatenation


Concatenation

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

Extracting Character and Concatenation

Program

Extracting Character and Concatenation


Program Source

public class Javaapp {

    public static void main(String[] args) {

        String str = "ABCDEFG";
        char c = str.charAt(3);
        System.out.println("c -> "+str.charAt(3));
        String str1 = "ABCD";
        String str2 = str1.concat("EFGH");
        System.out.println("str2 -> "+str2);
    }
}

Leave a Comment