android - how can I split an arraylist to multiple strings? -


i have split arraylist in multiple strings in app should display in order..

            arraylist<string> contactlist = new arraylist<string>();             contactlist.add("prasad");             contactlist.add("prasad");             contactlist.add("prasad");             contactlist.add("prasad");              string[] contact = new string[contactlist.size()];             contact = contactlist.toarray(contact);              stringbuffer sb = new stringbuffer("");              (string s : contactlist) {                 sb.append(s+",");             }              stringtosend = sb.tostring();              log.d("stringtosend ", stringtosend);              new upload().execute();              /*              * string[] rstring = stringtosend.split("-");              *               * (string s : rstring) { system.out.println("names : " +              * s); }              */          }     }); }  class upload extends asynctask<void, void, void> {      string res, res1, url;     progressdialog pd;      protected void onpreexecute() {         pd = progressdialog.show(mainactivity.this, "sending",                 "please wait");     }      @override     protected void doinbackground(void... params) {         // todo auto-generated method stub          try {             res = null;             url = "http://192.168.0.40:8092/testing/login";              //res = customhttpclient.executehttpget(url).trim();              arraylist<namevaluepair> namevaluepairs = new arraylist<namevaluepair>();             namevaluepairs.add(new basicnamevaluepair("name", stringtosend));              res = customhttpclient.executehttppost(url, namevaluepairs);          } catch (exception e) {             // todo: handle exception         }         return null;     }      protected void onpostexecute(void unused) {         pd.dismiss();            if (res != null) {              toast.maketext(mainactivity.this, "res", 1000).show();         }      } 

i getting response prasad,prasad,prasad,prasad

i should response

prasad

prasad

prasad

prasad

how do this?

change for loop. do.

  (string s : contactlist) {                 sb.append(s+"\n");             } 

edit:

convert arraylist string array.

string[] myarray = (string[])list.toarray(typeof(string)); 

now myarray variable has prasad values

you can access myarray[0] , myarray[1] ... directly or using loop.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -