String address=null; String body = ""; String date = ""; for(int i = 0; somecondition; i++) { body = cursor.getBody(i); //and so on all strings get changed //REST OF THE CODE }
This loops for arround 500 times so what should I use?
Example makes no sense. Every loop iteration does the same thing, without looking at i. There is no String being built/concatenated. What is the question?
I can't see the point of this, since by the end of the loop body, address, etc. will just have the same value as it did right before the loop ended... So why is the loop there in the first place? (assuming cursor.getBody(i) doesn't change the state of the your program)
Given that nothing changes in the String you are just reassigning it, use a String. StringBuilder is used when you want to build up a String in pieces.
Sign up to request clarification or add additional context in comments.
Comments
2
Since you're just assigning some string to the variable, just use String instead of StringBuilder. StringBuilder as its name suggest, is used for building a new string where concatenation or manipulation is desired.
StringBuilder.i. There is no String being built/concatenated. What is the question?body,address, etc. will just have the same value as it did right before the loop ended... So why is the loop there in the first place? (assumingcursor.getBody(i)doesn't change the state of the your program)