Results 1 to 2 of 2
  1. #1
    emgee is offline Member
    Join Date
    Nov 2010
    Posts
    1
    Rep Power
    0

    Default SORT list on items where frequencies are involved

    Hi,

    I have in a list items looking like this:

    Jane (4)
    John (7)
    Ann (3)
    Michael (16)

    The result i want to become is this one:

    Michael (16)
    John (7)
    Jane (4)
    Ann (3)


    How can i solve this problem?

    Kind Regards,
    emgee

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Are the data elements objects of a class? In other words do you have a class that holds String name and int frequency? If so, make that class implement the Comparable<T> interface, in the compareTo method, return 1, 0, or -1 depending how the frequency of one object compares to the frequency of this object, and then sort the list using Collections.sort(...).

Similar Threads

  1. Transfering all items from one List to another
    By Bulelakes in forum New To Java
    Replies: 6
    Last Post: 08-23-2010, 08:48 AM
  2. List of Items in JTextArea
    By ŖΫ ỏ Ңόρę in forum New To Java
    Replies: 7
    Last Post: 03-15-2010, 09:03 PM
  3. [SOLVED] Insertion Sort in Linked List
    By taylorp in forum New To Java
    Replies: 10
    Last Post: 03-27-2009, 12:34 AM
  4. different sort of items
    By jrleonard in forum SWT / JFace
    Replies: 0
    Last Post: 12-23-2008, 02:41 PM
  5. How to sort a list using Bubble sort algorithm
    By Java Tip in forum Algorithms
    Replies: 3
    Last Post: 04-29-2008, 08:04 PM

Posting Permissions

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