When you concatenate strings using the + operator in Java, a new String object is created. Here's what happens step by step:
1.String Immutability: In Java, String is immutable, meaning once a String object is created, it cannot be changed. So, when you concatenate two strings using the + operator, Java creates a new String object to hold the result of the concatenation.
2.StringBuilder/ StringBuffer: Behind the scenes, the Java compiler often optimizes string concatenation by using a StringBuilder or StringBuffer (depending on whether the operation is synchronized). When concatenating strings in a loop or multiple times, this helps avoid creating many intermediate String objects.