-3

In my java program i have created a Vector of user defined type Vector<PolledData> poll=null;. The Vector is of type of instance of class PolledData. I need to sort the Vector poll, I tried Collections.sort(poll);,but it didn't work.

Is there a any way to sort the vector poll?

CloudPotato
  • 1,255
  • 1
  • 17
  • 32

2 Answers2

1

The Solution is:

Collections.sort(poll, new Comparator<PolledData>() {
        @Override
        public int compare(final PolledData object1, final PolledData object2) {
            return object1.getName().compareTo(object2.getName());
        }
       } );

Now the elements in my Vector poll is sorted.

0

You need to implement Comparable / Compactor for pojo which are being stored in vector.

Dark Knight
  • 8,218
  • 4
  • 39
  • 58