Java String concat

java string concatenationJava String Concatenation-

Java String con­cate­na­tion is the way of merg­ing tow string into one string. You can append one string with anoth­er string in two ways.

  1. Using con­cat() method.
  2. Using ‘+’ oper­a­tor.

Prototype-

Write a text program to concat “abc” with “def”.

In this above pro­gram 3 objects are cre­at­ed.

  1. abc” in String con­stant pooled area.
  2. argu­ment String object “def” in String con­stant pooled area.
  3. Result String object “abcdef” in the Heap Area.

Unlike con­cat() method ‘+’ oper­a­tor always return new object.(Read Also : String replace in java)

Internal implementation of java string concat-