1
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?

7
  • If you are trying to build a string, I would recommend StringBuilder. Commented Sep 30, 2011 at 4:42
  • Want to assign value then use String type. Commented Sep 30, 2011 at 4:43
  • 1
    Please reread your example code as several things don't make sense. It will also help for you to better explain the situation. Commented Sep 30, 2011 at 4:43
  • 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? Commented Sep 30, 2011 at 4:43
  • 1
    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) Commented Sep 30, 2011 at 4:49

3 Answers 3

3

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.

Comments

2

Your example doesn't build any String, just going assign values. In that case you can use String

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.