Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ArrayList Custom Sort Order

 
arunkumar subramanian
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 12021
25
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
arunkumar subramanian
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 12021
25
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this may sound dumb, but why don't you just add them in the order you want them?
 
arunkumar subramanian
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic