Java String concatenation is the way of merging tow string into one string. You can append one string with another string in two ways.
- Using concat() method.
- Using ‘+’ operator.
Write a text program to concat “abc” with “def”.
In this above program 3 objects are created.
- “abc” in String constant pooled area.
- argument String object “def” in String constant pooled area.
- Result String object “abcdef” in the Heap Area.
Unlike concat() method ‘+’ operator always return new object.(Read Also : String replace in java)