Re: SortedList ?

Discussion in 'Java' started by Phil Hanna, Jul 2, 2003.

  1. Phil Hanna

    Phil Hanna Guest

    On 1 Jul 2003 01:25:03 -0700, (Meir) wrote:

    >You have got to be kidding: No SortedList in Java2 ?
    >I to implement a priority-queue, that accepts an Object and a priority
    >integer, and inserts this "job" to the queue, with the specified
    >priority.
    >
    >Please note: Duplicate priorities are abviously allowed!
    >
    >I only found a SortedMap (no dups).
    >
    >I don't want to use a regular list and keep sorting it
    >each time.
    >
    >How is it done in Java2 ?
    >


    Use an ordinary ArrayList and insert new items in the proper location
    using:

    Collections.binarySearch(list, key, comparator);

    to find the proper insertion spot.

    If priorities change (so that the order changes), sort the list in
    place with

    Collections.sort(list, comparator);


    --
    Phil Hanna
    Author of JSP 2.0: The Complete Reference
    http://www.philhanna.com
    http://www.philhanna.com
     
    Phil Hanna, Jul 2, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nathan Sokalski

    Problem with SortedList

    Nathan Sokalski, May 30, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    1,880
    Karl Seguin
    May 30, 2005
  2. Thomas Weidenfeller

    Re: SortedList ?

    Thomas Weidenfeller, Jul 1, 2003, in forum: Java
    Replies:
    3
    Views:
    2,866
    Tim Tyler
    Jul 10, 2003
  3. B-rad the Beat Nick

    SortedList: best practices with java 1.5

    B-rad the Beat Nick, Nov 4, 2005, in forum: Java
    Replies:
    5
    Views:
    113,058
    Roedy Green
    Nov 5, 2005
  4. sck10
    Replies:
    4
    Views:
    424
    sck10
    Sep 26, 2006
  5. jc
    Replies:
    1
    Views:
    708
    sloan
    Jul 15, 2008
Loading...

Share This Page