1

How can I send a string to a server as a request? After getting response, I should again split the string in to parts. I have stored an ArrayList into string here:

ArrayList<String> contactlist=new ArrayList<String>();
        contactlist.add("Android");
        contactlist.add("tarnaka");
        contactlist.add("uppal");
        contactlist.add("Prasad");

        String[] contact=new String[contactlist.size()];
        contact=contactlist.toArray(contact);
Carl Veazey
  • 18,342
  • 8
  • 64
  • 81
Adi
  • 13
  • 4

4 Answers4

0

By using json array you can pass it to the server, Try this link,

How to send a JSON object over Request with Android?

Community
  • 1
  • 1
shiju B
  • 1,690
  • 10
  • 23
0

To join ArrayList into a string Use

String joined = TextUtils.join(",", contactslist.toArray()); 

See: http://developer.android.com/reference/android/text/TextUtils.html#join(java.lang.CharSequence, java.lang.Object[])

M-Wajeeh
  • 16,948
  • 10
  • 63
  • 98
0

Make a string by inserting "-" in between of ArrayList objects. Sent that string. For getting the array of names call string.split("-")enter code here`at other end. You r done.

Jatin Malwal
  • 4,887
  • 2
  • 22
  • 26
0

Here u are...

ArrayList<String> contactlist = new ArrayList<String>();
    contactlist.add("Android");
    contactlist.add("tarnaka");
    contactlist.add("uppal");
    contactlist.add("Prasad");

    StringBuffer sb = new StringBuffer("");

    for (String temp : contactlist) {
        sb.append("-" + temp);
    }

    String stringToSend = sb.toString();

    MyLog.printLog("String : " + stringToSend);

    String[] rString = stringToSend.split("-");

    for (String s : rString) {
            MyLog.printLog("Names : " + s);
    }
Jatin Malwal
  • 4,887
  • 2
  • 22
  • 26