+ 1
Java String + operator
so i have the below code as an example and want to know what exactly happens. so i have 3 strings: 2 initialized with the same length and one with the total length. if i say c = a + b what exactly happens? is there a new string object created by the + operator or are the 2 values just copied? https://code.sololearn.com/c1giuHJRv1P7/?ref=app
5 Answers
+ 3
you are concatenating the strings stored in a and b and then assigning it to c.
and for the next question you are overwriting if c already consists of a string
+ 2
This creates a new string đ
String c,b,a = "test1";
b = "test2";
c = new String (a + b);
System.out.println(c);
+ 1
your just assigning c to use the values of a and b its called string concatenation
0
yea but internal is it creating a new string or not?
0
does it create a new string if the c already has a value and im just overwriting it?