String Operator

There is only one string operator: the concatenation operator (+). The concatenation
operator for strings works very similarly to the addition operator for numbers–it adds
strings together.

The Concatenation class

class Concatenation
{
public static void main (String args[])
{
String firstHalf = “What ” + “did “;
String secondHalf = “you ” + “say?”;
System.out.println(firstHalf + secondHalf);
}

}

The output of Concatenation follows:
What did you say?
Output

In the Concatenation program, literal strings are concatenated to make assignments to
the two string variables, firstHalf and secondHalf, at time of creation. The two string
variables are then concatenated within the call to the println() method.

Scroll to Top