Wednesday 28 August 2013

Java String operation - Writing efficient code

Java String operation - Writing efficient code

First of all, I am not a experienced java developer. The problem is My sql
query give return data like this ABC BCD DEF EFG. But, I want to add ,
after the every entry So, I was tried with this
if (cursor != null) {
cursor.moveToFirst();
do {
if (cursor.getPosition() == 0) {
getName =
cursor.getString(cursor.getColumnIndexOrThrow("NAME"));
} else {
getName = getName + ","
+
cursor.getString(cursor.getColumnIndexOrThrow("NAME"));
}
} while (cursor.moveToNext());
}
My question is is it okay or is there any way to write this code
efficiently(Like achiving the same goal by writing less line of code).
Thank you.

No comments:

Post a Comment