Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Sorting a string with numbers

  1. #1
    Junior Member
    Join Date
    Jun 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Sorting a string with numbers

    Hi All,

    Im trying to sort the below array in jsp.

    var arr = ["5:1313847962519,1313847955548","20:1313847964244" ,"4:1313847962466","11:1313847965024,1313847938900 "];

    I want the output as
    4:1313847962466
    5:1313847962519,1313847955548
    11:1313847965024,1313847938900
    20:1313847964244

    NOTE: All I need to look into is the numbers before the character ":" and sort it.

    This code does not work.
    var order = arr.sort(function (a, b) {
    return ( a-b );
    });

    Could anyone please suggest me how to do this?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,580
    Thanks
    49
    Thanked 2,233 Times in 2,205 Posts

    Default Re: Sorting a string with numbers

    Are you going to write a java program to do this? The code looks like javascript.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jun 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Sorting a string with numbers

    Not java program. I need to do this in javascript.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,580
    Thanks
    49
    Thanked 2,233 Times in 2,205 Posts

    Default Re: Sorting a string with numbers

    Moved out of java programming section.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. [SOLVED] Sorting multiple digit numbers
    By keepStriving in forum Java Theory & Questions
    Replies: 1
    Last Post: November 16th, 2013, 06:40 PM
  2. Replies: 6
    Last Post: October 26th, 2013, 01:59 PM
  3. STRING sorting plz correct it
    By Rawezh Frya in forum What's Wrong With My Code?
    Replies: 9
    Last Post: November 27th, 2012, 11:05 AM
  4. Sorting Formatted Numbers In JTable
    By aussiemcgr in forum Java Theory & Questions
    Replies: 1
    Last Post: August 10th, 2011, 09:40 PM
  5. Help with sorting numbers
    By planktonx in forum Collections and Generics
    Replies: 2
    Last Post: October 5th, 2010, 08:01 AM