android - Java String operation - Writing efficient code -


first of all, not experienced java developer. problem sql query give return data abc bcd def efg. but, want add , after every entry so, tried this

if (cursor != null) {             cursor.movetofirst();             {                  if (cursor.getposition() == 0) {                      getname = cursor.getstring(cursor.getcolumnindexorthrow("name"));                  } else {                      getname = getname + ","                             + cursor.getstring(cursor.getcolumnindexorthrow("name"));                 }              } while (cursor.movetonext());         } 

my question is okay or there way write code efficiently(like achiving same goal writing less line of code). thank you.

how this:

mystring = "abc bcd def efg"; string newstring = mystring.replace(" ", ", "); system.out.println(newstring); 

output:

abc, bcd, def, efg 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -