File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes ArrayList Custom Sort Order Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "ArrayList Custom Sort Order" Watch "ArrayList Custom Sort Order" New topic
Author

ArrayList Custom Sort Order

arunkumar subramanian
Ranch Hand

Joined: Jun 10, 2008
Posts: 32
Hi

How to sort an ArrayList based on custom order.



I want to sort this list like "Two", "Three", "One", "Five", "Four". Comparator works on natural sort order. How can I achive this?
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11167
    
  16

what is this order? can you logically define how these elements are sorted, or is just an absolute?

what happens when you add in "Six", "Seven" and "Eight"?

I guess what I'm saying is that i don't see what order these are in, so it's kind of hard to come up with a way to tell the JVM to do it...


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
arunkumar subramanian
Ranch Hand

Joined: Jun 10, 2008
Posts: 32
It is an absolute ordering. I have a predefined set of information and the arraylist will contain only that data.



There can be duplicate entries in the arraylist, but there will not be any value apart from these.


[ July 03, 2008: Message edited by: arunkumar subramanian ]
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11167
    
  16

this may sound dumb, but why don't you just add them in the order you want them?
arunkumar subramanian
Ranch Hand

Joined: Jun 10, 2008
Posts: 32
I just took the core of what I need. I will give a try and see. Thanks for your input.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ArrayList Custom Sort Order
 
Similar Threads
regex problem
How do I assign variables with values from a list?
JTable Horizontal Scrolling Probs
Iteration speed of Collections
poll(),peek() in PriorityQueue class