I have one question.
When we do
String str = "abc";
"abc" will become string literal and will reside under string pool.
If we have string in for loop like below:
private static void doByString() {
String str;
for(long l = 0; l < Long.MAX_VALUE; l++){
str = str + "" + l;
}
}
It will be making a lot of string literals, and we have to use it in for loop.
In this type of situation, can we do something to minimize the making of string literals?
Can we use string builder in this case like :
private static void boByStringBuilder() {
StringBuilder builder = new StringBuilder();
for(long l = 0; l < Long.MAX_VALUE; l++){
builder.append(l + "");
}
}