Is String Concatenation memory efficient? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Is String Concatenation memory efficient?

Which is more memory efficient: Concatenating two Strings, or just having one String with both values in it? My code below gives an example of both cases. Thank you in advance. https://code.sololearn.com/cdqv4F5k2GWF/?ref=app

24th Jun 2018, 12:51 PM
mauricio nunez
3 Answers
0
Of course creating less variables is more memory efficient so if you can have one string don't create two of them.
24th Jun 2018, 1:09 PM
Krzysztof303
Krzysztof303 - avatar
0
Ok, then what about String x = “HelloWorld”; String y = “Hello” + “World”; Which is more efficient. x or y?
24th Jun 2018, 1:25 PM
mauricio nunez
0
this is the same
24th Jun 2018, 2:59 PM
Krzysztof303
Krzysztof303 - avatar