Concatenation

Definition

Concatenation is the combination of strings. In Java, to combine strings, one must use the "+" symbol.

Examples

System.out.print("I am" + 18 + "years old");

This will evaluate to
I am 18 years old

System.out.print("I am" + 1 + 8);

This will evaluate to
I am 18

System.out.print(1 + 8 + "I am" );

This will evaluate to
9 I am

System.out.print("I am" + 10 + 8 + "years old");

This will evaluate to
I am 108 years old

System.out.print("I am" + (10 + 8) + "years old");

This will evaluate to
I am 18 years old

System.out.print(18 + "is my age");

This will evaluate to
18 is my age

System.out.print("Ten plus eight is" + 10 + 8);

This will evaluate to
Ten plus eight is 108

System.out.print("Ten plus eight is" + 1 + 8);

This will evaluate to
Ten plus eight is 18
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License