What is more efficient to use for appending data to string
String a= string.format("xx %s xx",yyy);
or
String b =xx+yyy+xxx;
?
What is more efficient to use for appending data to string
String a= string.format("xx %s xx",yyy);
or
String b =xx+yyy+xxx;
?
String a= string.format("xx %s xx",yyy);
It will replace yyy
to %s
for that it require pare whole string and then create new string object. so less efficient then concatenation xx+yyy+xxx;
.
Appending using operators is generally more efficient. Format has to take the string and find "%"'s and so, and replace them with corresponding values. Appending is simpler, and shorter to type!
Imagine you are the compiler.
Go through the string to find the %s symbol. Replace it with the value there. Then concatenate.
Concatenate.