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

    Default SORT list on items where frequencies are involved


    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,

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power


    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, 09:48 AM
  2. List of Items in JTextArea
    By ŖΫ ỏ Ңόρę in forum New To Java
    Replies: 7
    Last Post: 03-15-2010, 10:03 PM
  3. [SOLVED] Insertion Sort in Linked List
    By taylorp in forum New To Java
    Replies: 10
    Last Post: 03-27-2009, 01:34 AM
  4. different sort of items
    By jrleonard in forum SWT / JFace
    Replies: 0
    Last Post: 12-23-2008, 03: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, 09: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