Results 1 to 2 of 2
  1. #1
    ExX is offline Member
    Join Date
    Feb 2012
    Rep Power

    Default Question about sorting in ArrayList

    Lets say I have an ArrayList of books that holds some data about a few book's title, author and page count, and I want to ask the user if they want to sort by Title or Author or Page Count, is it possible to sort by using ArrayList or should I use simple Array? Because Title and Author will be sorting by String and Page Count will be sorting by integer, i just don't know if ArrayList can do that kind of sorting, i hope my question is understandable...

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

    Default Re: Question about sorting in ArrayList

    Look at the java.util.Collections class API and you'll find some sort methods that work well on ArrayLists. You'll likely need to use some Comparators to allow you to sort on different fields.

Similar Threads

  1. Replies: 8
    Last Post: 08-13-2011, 06:02 PM
  2. sorting arraylist based on another arraylist
    By busdude in forum New To Java
    Replies: 4
    Last Post: 02-07-2011, 11:48 AM
  3. Java ArrayList : Generics & Sorting
    By Eranga in forum Java Tutorial
    Replies: 0
    Last Post: 10-19-2010, 04:43 AM
  4. Sorting ArrayList by object data
    By drymsza1234 in forum New To Java
    Replies: 2
    Last Post: 04-15-2010, 01:22 AM
  5. Sorting an ArrayList
    By flesh-bound-book in forum New To Java
    Replies: 3
    Last Post: 02-13-2010, 12:20 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