In my program an array fClasses of fixed length [7] of objects is created, each object is a class FClass that contains 3 Strings, an <
You have to create a Comparator, rather than use a Comparable.
public class FClassComparator implements Comparator
{
public int compare(FClass left, FClass right) {
// Swap -1 and 1 here if you want nulls to move to the front.
if (left == null) return right == null ? 0 : 1;
if (right == null) return -1;
// you are now guaranteed that neither left nor right are null.
// I'm assuming avg is int. There is also Double.compare if they aren't.
return Integer.compare(left.avg, right.avg);
}
}
Then call sort via:
Arrays.sort(fClassArray, new FClassComparator());