Java-String Concatenation

String Concatenation

Java defines one operator for string object such as “+”, it is used to concatenate two string. For example, in the following program, the value of the variable ‘a’ and ‘b’ is being converted to a string that represents this value as a decimal digit character. This is prompted by the fact that it is combined with the string literal, “ “, using the + operator.

Program

Program Source

public class Javaapp {

    public static void main(String[] args) {
       
        int a = 50,b = 100;
        String str1 = new String("a = "+a+" and b = "+b);
        System.out.println(str1);
    }
}

Leave a Comment