<<< The Comparable interface | Index | How to create a reference to an array >>> |
Code that sorts an array of Item objects
Item[] items = new Item[3]; items[0] = new Item(102, "Duct Tape"); items[1] = new Item(103, "Bailing Wire"); items[2] = new Item(101, "Chewing Gum"); Arrays.sort(items); for (Item i : items) System.out.println(i.getNumber() + ": " + i.getDescription());
The console output
101: Chewing Gum 102: Duct Tape 103: Bailing Wire
<<< The Comparable interface | Index | How to create a reference to an array >>> |