Home Java multiline string formation
Reply: 0

Java multiline string formation

user700
1#
user700 Published in May 23, 2018, 6:40 pm

I'm by no means a java programmer, so this may seem pretty basic.

Which of these are 'better' when you want to keep your code lines short.

String str = "First part of a string.";
str += " Second part of string.";

or

String str = "First part of string." +
" Second part of string."

I guess my question is do both the += and + make a new String object? If they do then neither really are better, it would just be a matter of preference. The example I gave would be a good example of real world use. I don't want a comparison of doing a concatenation 3 times to 1000 times with either method.

Thanks

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.391687 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO