0

I was a C programmer so I am new to Java and I was looking for a way to sort the arrays of objects I have created or maybe arraylist of objects (say of 10 objects)

I have been searching over the Internet but I got only comparison of two objects at a time on the basis of age(say) but none are for 10 objects. I tried using bubble sort but I am unable to change the order of objects in arraylist or array like I used to do in C.

Well geocodezip suggested the use of Collections.sort but I am getting compile time error

int cannot be dereferenced.

class Party
{
int count=0;
String name=null;
public static Comparator<Party> COMPARE_BY_COUNT =new Comparator<Party>()
{
public int compare( Party p,Party other)
 {
 return p.count.compareTo(other.count);
      }
     };

}
void bubsort(ArrayList<Party>partieslist)

{
//List<Party> partieslist=new ArrayList<Party>();
    Collections.sort(partieslist,Party.COMPARE_BY_COUNT) ;
}

 

0 Answers0