×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Regular Contributor
    Join Date
    Mar 2009
    Location
    Delhi
    Posts
    223

    sort j2me vector

    how to sort a vector in j2me? there is no java.util.Collections class
    how do i sort thn
    Thanx
    Pooja

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: sort j2me vector

    You will need to code your own sorting algorithm.

    For example, try a bubble sort, which, in spite of it's bad reputation, tends to perform quite well in interpretted Java for short lists (<30 items), and has the advantages of being small, simple, and has very little memory overhead. However, it's best performed on an array, not a Vector. There are many other algorithms.

    Graham.

  3. #3
    Regular Contributor
    Join Date
    Mar 2009
    Location
    Delhi
    Posts
    223

    Re: sort j2me vector

    i want to sort a vector which contains list of strings. its easy to sort in bubble if vector contains all integer values. i have a vector list of string.
    Thanx
    Pooja

  4. #4
    Registered User
    Join Date
    Nov 2009
    Posts
    188

    Re: sort j2me vector

    You have to sort manually by using the equals() or compareTo method.

  5. #5
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: sort j2me vector

    Quote Originally Posted by poojs View Post
    i want to sort a vector which contains list of strings. its easy to sort in bubble if vector contains all integer values. i have a vector list of string.
    Hello poojs,
    If your vector contain all the string at the all indexes,then you can get the string value and then calculate the string length and then as per your requirement you can code your own logic.

    or you can convert the String in the int value
    int aInt = Integer.parseInt(aString);
    and you can move ahead.
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  6. #6
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: sort j2me vector

    Quote Originally Posted by poojs View Post
    i want to sort a vector which contains list of strings. its easy to sort in bubble if vector contains all integer values. i have a vector list of string.
    Quote Originally Posted by ajitkumar26 View Post
    You have to sort manually by using the equals() or compareTo method.
    He's right.

    For integers, the comparison would be:

    Code:
    if (a < b) {
        // swap a and b
    }
    For Strings, the equivalent is:

    Code:
    if (a.compare(b) < 0) {
        // swap a and b
    }
    Or, change "<" to ">" for the opposite order.

    For other kinds of object, you'd need to define a concept of "less than" or "greater than".

    Graham.

Similar Threads

  1. J2ME or C++ for VoIP on Mobile
    By sandeepkumar03 in forum VoIP
    Replies: 4
    Last Post: 2009-02-02, 10:28
  2. Calling a native c or c++ application from J2ME
    By satyarajasekhar in forum Mobile Java Networking & Messaging & Security
    Replies: 5
    Last Post: 2009-01-02, 12:10
  3. J2ME or C++ for VoIP on Mobile Phone
    By sandeepkumar03 in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2008-11-13, 20:14
  4. Acessing voice channel using J2ME
    By diegomello in forum VoIP
    Replies: 1
    Last Post: 2008-10-21, 15:57
  5. Can J2ME be used for sending MMS Message ?
    By seno_ap in forum Mobile Java General
    Replies: 1
    Last Post: 2006-11-24, 14:36

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×