java - How to write data to a String when in a for-loop -


so have database loop. gives different score every time, need save string (or file, guess string easier, because need empty @ every new call database).

i want store scores going through loop, , adding , after each score (to keep them seperate) code isn't working because part of code outside loop. how fix this? or there better/other methods want create?

databasehandler db = new databasehandler(camera.this); list<database> contacts = db.getallcontacts(); (database contact : contacts) {     string test = contact.getmp();     stringwriter stringwriter = new stringwriter();     printwriter printwriter = new printwriter(stringwriter);     printwriter.println(test); }   printwriter.flush(); printwriter.close(); return stringwriter.tostring(); 

try this:

stringbuilder sb = new stringbuilder(); (database contact : contacts) {      if(sb.length > 0) {         sb.append(", ");     }     sb.append(contact.getmp()); } ... sb.tostring(); 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -