Re: missing pieces

Discussion in 'Java' started by raf, Jul 11, 2003.

  1. raf

    raf Guest

    On Mon, 07 Jul 2003 23:17:36 GMT, Roedy Green <> wrote:

    > Is there such thing as a sorted ArrayList that just keeps itself in
    > order? When you add it does a binary search. When you add an entire
    > array it does a merge.


    check out the TreeBag in the Apache Commons Collections classes. it should
    provide the features you're looking for.

    > Is there such as thing as a sorted JTree that keeps the nodes in
    > alphabetical order?


    It should be pretty straightforward to design a TreeModel implementation
    that can do this.


    > Is there such thing as a merge that merges two sorted arrays into one?
    > It might use binary search when the sizes are very different to find
    > the insertion points.


    This should be simple to do by having the Arrays class convert them to
    lists and then add the lists to a sorted collection class, for example:

    import org.apache.commons.collections.TreeBag;
    import java.util.Arrays;
    // ...
    public static Object[] merge(Comparable[] a, Comparable[] b) {
    TreeBag tempBag = new TreeBag(Arrays.asList(a));
    tempBag.addAll(Arrays.asList(b));
    return tempBag.toArray();
    }

    Cheers,

    raf
    --
    Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
     
    raf, Jul 11, 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. John Spiegel

    Tying the pieces (files) together

    John Spiegel, Aug 27, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    394
    John Spiegel
    Aug 29, 2003
  2. =?Utf-8?B?UENL?=

    1 large application versus many smaller pieces

    =?Utf-8?B?UENL?=, May 27, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    424
    =?Utf-8?B?RGV2R3V5?=
    May 27, 2005
  3. Jay
    Replies:
    11
    Views:
    717
    Nick Landsberg
    Feb 25, 2004
  4. gregonans
    Replies:
    0
    Views:
    292
    gregonans
    Jun 11, 2004
  5. David Mathog
    Replies:
    26
    Views:
    1,335
    Ian Collins
    Jun 9, 2011
Loading...

Share This Page