0

Possible Duplicate:
Sorting ArrayList of Objects by Object attribute

Basically I have an ArrayList that stores objects, each of those objects has a field that stores an integer. I want to store the objects in my ArrayList by acending order of that integer.

Is there an easy way to do this, I've looked around the Java API doc but can't find anything that looks suitable, sorry if this is trivial but it sounds like it should be simple enough if I can just find the right documentation.

Thanks

Community
  • 1
  • 1
user1357063
  • 39
  • 1
  • 2
  • 5
  • Did you try searching on google, using your title as search statement? Sure you will get lot of questions on this topic on SO only. – Rohit Jain Nov 25 '12 at 12:25

1 Answers1

0

Create your custom comparator class implementing java.util.Comparator and use java.util.Collections.sort(list, comparator).

Aleksandr M
  • 24,264
  • 12
  • 69
  • 143
  • 1
    Please improvise over this answer. – Rohit Jain Nov 25 '12 at 12:25
  • @Alexsandr.. Yeah, improvise in the sense, either add an example, or quote a link, so that OP can know how exactly this is done. Of course he won't have any idea about how to use them. – Rohit Jain Nov 25 '12 at 12:34
  • "Improvise in the sense"? How exactly implement class? Or how to call a method? All is pretty straight forward in Java. – Aleksandr M Nov 25 '12 at 12:38
  • @Aleksandr.. Understand that what looks straight forward to you, might not be the same for OP, else he would have solved his problem himself. And common, I'm just saying you to improvise, to make your answer better. If you don't want to give better answers, please don't argue. And I think, we should stop this chat now. – Rohit Jain Nov 25 '12 at 12:41