79480011

Date: 2025-03-03 01:44:57
Score: 1.5
Natty:
Report link

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.

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Starts with a question (0.5): When you
  • Low reputation (1):
Posted by: Gursewak Singh Chahal