You can only use the sort method of the Arrays class to sort arrays of objects when the classes for those objects implement the Comparable interfce.
the method compareTo(Object o) must be implemented.
An Item class that implements the Comparable interface
public clas Item implements Comparable } private int number; private String description; public Item(int number, String description) { this.number = number; this.description = description; } public int getNumber() { return number; } public int getDescription() { return description; } public int compareTo(Object 0) { Item i = (Item)o; if (this.getNumber() < i.getNumber()) return -1; if (this.getNumber() > i.getNumber()) return 1; return 0; } }Code that sorts an array of Item objects
Item[] items = new Item[3]; items[0] = new Item(101, "duck"); items[1] = new Item(102, "rabbit"); items[2] = new Item(103, "fox"); Arrays.sort(items); for (Item i : items) { System.out.println(i.getNumber() + ": " + i.getDescription()); }