Hello all,
I am retrieving data from servlet to midlet. Now coming data is whole string. but now I want to chop it into different words. here my code is :

HttpConnection conn = (HttpConnection) Connector.open(url);
               StringBuffer sb = new StringBuffer();
               conn.setRequestProperty("Content-Type", "Application/x-urlformencoded");
               InputStream is = conn.openInputStream();
               byte[] b = new byte[(int) conn.getLength()];
               int ch = 0;
               while ((ch = is.read()) != -1) {
                  sb.append((char) ch);


and the output is







But now I want each word and append them into list. What can I do?

Recommended Answers

All 2 Replies

This page from rim gives examples of string utility functions for j2me, the first on the page (split) should do the trick

commented: Thanx for sharing +16

Thanks burgercho. Its really Helpful. Even I found one code.

public static String[] stringToArray(String a, String delimeter) {
      String c[] = new String[0];
      String b = a;
      while (true) {
         int i = b.indexOf(delimeter);
         String d = b;
         if (i >= 0) {
            d = b.substring(0, i);
         String e[] = new String[c.length + 1];
         for (int k = 0; k < c.length; k++) {
            e[k] = c[k];
         e[e.length - 1] = d;
         c = e;
         b = b.substring(i + delimeter.length(), b.length());
         if (b.length() <= 0 || i < 0) {
      return c;

This is also working.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.