sorting objects in java
Hi is it possible to sort objects in java by a particular attibute. For eg. I have several 'user' objects which have an attribute say empno which is a numeric. Is it possible to sort all the user objects in ascending order by emp no. If yes, then how,
What have you tried? How are the Objects stored? In a List? In an array? As separate variables?
You could write a sorting method yourself. Or you could implement Comparable. Or you could set up a Comparator. Google and the API are your friends.
I agree with Kevin. You should read up on how to implement the Comparable interface in your class. Please see link to API for Comparable: Comparable (Java 2 Platform SE v1.4.2)
thanks! the objects are stored in a arraylist.