1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| import java.util.*;
class Item { public int age;
public Item(int age) { this.age = age; }
public int getAge() { return this.age; } }
public class Test {
public static void main(String[] args) { Collection<String> names = new ArrayList<>();
Collections.addAll(names, "1", "2", "3");
List<String> names1 = new ArrayList<>(); Collections.addAll(names1, "2", "5"); Collections.shuffle(names1);
List<Integer> scores = new ArrayList<>(); Collections.addAll(scores, 1, 2, 3, 7, 5, 3); Collections.sort(scores);
List<Item> items = new ArrayList<>(); Collections.addAll(items, new Item(1), new Item(1)); Collections.sort(items, new Comparator<Item>() { @Override public int compare(Item o1, Item o2) { return o1.getAge() - o2.getAge(); } }); } }
|