package com.sf._03_collections; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class Test { public static void main(String[] args) { /** * 排序 * Collections.sort(集合 要求集合当中元素要实现compareable几口); */ List list = new ArrayList<>(); list.add(2); list.add(1); list.add(5); list.add(4); list.add(3); Collections.sort(list); System.out.println(list); /** * 创建Student name age * 想要进行降序排序 */ List students = new ArrayList<>(); // students.add(new Student("zhangsan",30)); // students.add(new Student("zhangsan3",40)); // students.add(new Student("zhangsan2",20)); // students.add(new Student("zhangsan5",10)); Collections.sort(students); for (Student student : students) { System.out.println(student); } /** * binarySearch(list必须有序,查找元素) */ System.out.println(Collections.binarySearch(list, new Integer(1))); /** * Collections.min 最小值 max 最大值 */ System.out.println("最大值为:"+ Collections.max(list)); System.out.println("最小值为:"+ Collections.min(list)); // 获取年龄最大学生和年龄最小的学生 System.out.println(Collections.min(students)); } }