fanjialong 6 часов назад
Родитель
Сommit
bfddb18751
20 измененных файлов с 959 добавлено и 0 удалено
  1. 11 0
      java-base-project10/day20/day20.iml
  2. 86 0
      java-base-project10/day20/src/com/sf/_01_treeset_contact/Goods.java
  3. 58 0
      java-base-project10/day20/src/com/sf/_01_treeset_contact/Test.java
  4. 17 0
      java-base-project10/day20/src/com/sf/_02_arrays/Test.java
  5. 49 0
      java-base-project10/day20/src/com/sf/_02_arrays/_01_排序/Test.java
  6. 50 0
      java-base-project10/day20/src/com/sf/_02_arrays/_01_排序/User.java
  7. 73 0
      java-base-project10/day20/src/com/sf/_02_arrays/_02_search/Student.java
  8. 40 0
      java-base-project10/day20/src/com/sf/_02_arrays/_02_search/Test.java
  9. 16 0
      java-base-project10/day20/src/com/sf/_02_arrays/_03_fill/Test.java
  10. 66 0
      java-base-project10/day20/src/com/sf/_02_arrays/_04_copy/Test.java
  11. 50 0
      java-base-project10/day20/src/com/sf/_02_arrays/_04_copy/Test1.java
  12. 20 0
      java-base-project10/day20/src/com/sf/_02_arrays/_05_equlas/Test.java
  13. 91 0
      java-base-project10/day20/src/com/sf/_02_arrays/_06_array_convert_list/Student.java
  14. 22 0
      java-base-project10/day20/src/com/sf/_02_arrays/_06_array_convert_list/Test.java
  15. 55 0
      java-base-project10/day20/src/com/sf/_02_arrays/_06_array_convert_list/Test1.java
  16. 73 0
      java-base-project10/day20/src/com/sf/_03_collections/Student.java
  17. 49 0
      java-base-project10/day20/src/com/sf/_03_collections/Test.java
  18. 39 0
      java-base-project10/day20/src/com/sf/_03_collections/Test1.java
  19. 35 0
      java-base-project10/day20/src/com/sf/_03_collections/Test2.java
  20. 59 0
      java-base-project10/day20/src/com/sf/_03_collections/Test3.java

+ 11 - 0
java-base-project10/day20/day20.iml

@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="JAVA_MODULE" version="4">
+  <component name="NewModuleRootManager" inherit-compiler-output="true">
+    <exclude-output />
+    <content url="file://$MODULE_DIR$">
+      <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
+    </content>
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+  </component>
+</module>

+ 86 - 0
java-base-project10/day20/src/com/sf/_01_treeset_contact/Goods.java

@@ -0,0 +1,86 @@
+package com.sf._01_treeset_contact;
+
+public class Goods implements Comparable<Goods>{
+    private Long goodsId;
+    private String name;
+    private double price;
+
+    public Goods() {
+    }
+
+    public Goods(Long goodsId, String name, double price) {
+        this.goodsId = goodsId;
+        this.name = name;
+        this.price = price;
+    }
+
+
+    @Override
+    public int compareTo(Goods o) {
+        if(this.price > o.getPrice()){
+            return 1;
+        }else if(this.price < o.getPrice()){
+            return -1;
+        }else{
+            if(this.getGoodsId() > o.getGoodsId()){
+                return 1;
+            }else if(this.getGoodsId() < o.getGoodsId()){
+                return -1;
+            }else{
+                return 0;
+            }
+        }
+    }
+
+    /**
+     * 获取
+     * @return goodsId
+     */
+    public Long getGoodsId() {
+        return goodsId;
+    }
+
+    /**
+     * 设置
+     * @param goodsId
+     */
+    public void setGoodsId(Long goodsId) {
+        this.goodsId = goodsId;
+    }
+
+    /**
+     * 获取
+     * @return name
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * 设置
+     * @param name
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
+     * 获取
+     * @return price
+     */
+    public double getPrice() {
+        return price;
+    }
+
+    /**
+     * 设置
+     * @param price
+     */
+    public void setPrice(double price) {
+        this.price = price;
+    }
+
+    public String toString() {
+        return "Goods{goodsId = " + goodsId + ", name = " + name + ", price = " + price + "}";
+    }
+}

+ 58 - 0
java-base-project10/day20/src/com/sf/_01_treeset_contact/Test.java

@@ -0,0 +1,58 @@
+package com.sf._01_treeset_contact;
+
+import java.util.Comparator;
+import java.util.Map;
+import java.util.TreeMap;
+
+public class Test {
+    public static void main(String[] args) {
+        Goods goods = new Goods(1L,"电脑",10000);
+        Goods goods1 = new Goods(3L,"手机",4000);
+        Goods goods2 = new Goods(2L,"耳机",8000);
+        Goods goods3 = new Goods(4L,"洗衣机",4000);
+        // key Goods 商品  value 库存
+        TreeMap<Goods,Integer> map = new TreeMap<>();
+        map.put(goods,100);
+        map.put(goods1,100);
+        map.put(goods2,100);
+        map.put(goods3,100);
+
+        // 遍历map 观察排序结果
+        for (Map.Entry<Goods, Integer> goodsIntegerEntry : map.entrySet()) {
+            System.out.println(goodsIntegerEntry);
+        }
+        System.out.println("---------------------------------------");
+        TreeMap<Goods,Integer> goodsIntegerTreeMap = new TreeMap<>(new Comparator<Goods>() {
+            @Override
+            public int compare(Goods o1, Goods o2) {
+                if(o1.getPrice() > o2.getPrice()){
+                    return -1;
+                }else if(o1.getPrice() < o2.getPrice()){
+                    return 1;
+                }else{
+                    if(o1.getGoodsId() > o2.getGoodsId()){
+                        return 1;
+                    }else if(o1.getGoodsId() < o2.getGoodsId()){
+                        return -1;
+                    }else{
+                        return 0;
+                    }
+                }
+            }
+        });
+
+        goodsIntegerTreeMap.put(goods,100);
+        goodsIntegerTreeMap.put(goods1,100);
+        goodsIntegerTreeMap.put(goods2,100);
+        goodsIntegerTreeMap.put(goods3,100);
+
+        int count = 0;
+        for (Map.Entry<Goods, Integer> goodsIntegerEntry : goodsIntegerTreeMap.entrySet()) {
+            double price = goodsIntegerEntry.getKey().getPrice();
+            if(price >= 200){
+                count++;
+            }
+        }
+
+    }
+}

+ 17 - 0
java-base-project10/day20/src/com/sf/_02_arrays/Test.java

@@ -0,0 +1,17 @@
+package com.sf._02_arrays;
+
+import java.util.Arrays;
+
+public class Test {
+    public static void main(String[] args) {
+        int[] nums = {5,2,9,1,5,6};
+        Arrays.sort(nums);
+        System.out.println(Arrays.toString(nums));
+        System.out.println(Arrays.binarySearch(nums, new Integer(9)));
+        int[] newArr = Arrays.copyOf(nums, 8);
+        System.out.println(Arrays.toString(newArr));
+        newArr[newArr.length-2] = 10;
+        newArr[newArr.length-1] = 11;
+        System.out.println(Arrays.toString(newArr));
+    }
+}

+ 49 - 0
java-base-project10/day20/src/com/sf/_02_arrays/_01_排序/Test.java

@@ -0,0 +1,49 @@
+package com.sf._02_arrays._01_排序;
+
+import java.util.Arrays;
+import java.util.Comparator;
+
+public class Test {
+    /**
+     * Arrays 排序api
+     * sort(数组);  默认升序排序
+     * sort(数组,startIndex,endIndex)
+     * sort(数组, Comparator.reverseOrder());    降序操作
+     * sort(数组, new Compartor() 自己实现比较规则)
+     *
+     * 1 创建一个数组[2,1,3,4,5,10,8]
+     * 2 需求: 讲数组进行升序排序
+     * 3 需求: 查询索引为3-5 元素
+     * 4 需求: 讲数组进行降序排序
+     * 5 需求 创建User 类(name,age) 内容放到User[] 数组中
+     *   按照年龄进行降序排序
+     */
+    public static void main(String[] args) {
+        Integer[] arr = {2,10,30,4,51,8};
+        // 1 数组升序排序
+//        Arrays.sort(arr);
+        // 2 查看索引3-5 元素
+//        Arrays.sort(arr,2,6);
+//        System.out.println(Arrays.toString(arr));
+        // 3 对于数组进行降序排序
+        Arrays.sort(arr,Comparator.reverseOrder());
+        System.out.println(Arrays.toString(arr));
+        User[] users= {new User("zhangsan",20),
+                new User("lisi",10),new User("wangwu",30)};
+        Arrays.sort(users, new Comparator<User>() {
+            @Override
+            public int compare(User o1, User o2) {
+                if(o1.getAge() > o2.getAge()){
+                    return -1;
+                }else if(o1.getAge() < o2.getAge()){
+                    return 1;
+                }else{
+                    return 0;
+                }
+            }
+        });
+        System.out.println(Arrays.toString(users));
+    }
+
+
+}

+ 50 - 0
java-base-project10/day20/src/com/sf/_02_arrays/_01_排序/User.java

@@ -0,0 +1,50 @@
+package com.sf._02_arrays._01_排序;
+
+public class User {
+    private String name;
+    private int age;
+
+    public User() {
+    }
+
+    public User(String name, int age) {
+        this.name = name;
+        this.age = age;
+    }
+
+    /**
+     * 获取
+     * @return name
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * 设置
+     * @param name
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
+     * 获取
+     * @return age
+     */
+    public int getAge() {
+        return age;
+    }
+
+    /**
+     * 设置
+     * @param age
+     */
+    public void setAge(int age) {
+        this.age = age;
+    }
+
+    public String toString() {
+        return "User{name = " + name + ", age = " + age + "}";
+    }
+}

+ 73 - 0
java-base-project10/day20/src/com/sf/_02_arrays/_02_search/Student.java

@@ -0,0 +1,73 @@
+package com.sf._02_arrays._02_search;
+
+public class Student implements Comparable<Student> {
+    private String name;
+    private Integer  age;
+    private Double score;
+
+    public Student() {
+    }
+
+    public Student(String name, Integer age, Double score) {
+        this.name = name;
+        this.age = age;
+        this.score = score;
+    }
+
+    /**
+     * 获取
+     * @return name
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * 设置
+     * @param name
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
+     * 获取
+     * @return age
+     */
+    public Integer getAge() {
+        return age;
+    }
+
+    /**
+     * 设置
+     * @param age
+     */
+    public void setAge(Integer age) {
+        this.age = age;
+    }
+
+    /**
+     * 获取
+     * @return score
+     */
+    public Double getScore() {
+        return score;
+    }
+
+    /**
+     * 设置
+     * @param score
+     */
+    public void setScore(Double score) {
+        this.score = score;
+    }
+
+    public String toString() {
+        return "Student{name = " + name + ", age = " + age + ", score = " + score + "}";
+    }
+
+    @Override
+    public int compareTo(Student o) {
+        return (int) (o.getScore() - this.getScore());
+    }
+}

+ 40 - 0
java-base-project10/day20/src/com/sf/_02_arrays/_02_search/Test.java

@@ -0,0 +1,40 @@
+package com.sf._02_arrays._02_search;
+
+import java.util.Arrays;
+
+public class Test {
+
+    public static void main(String[] args) {
+        /**
+         *
+         * `static int binarySearch(数组, 目标元素)`
+         * 可以帮我们查询有序数组当中元素内容
+         * 需求:
+         *  有一个数组Integer [2,1,3,5,6,4]
+         *  想要查询5元素锁在位置 ,要利用arrays api 去完成
+         */
+//        Integer[] arr = {2,1,3,5,6,4};
+//        // 先排序变成有序数组
+//        Arrays.sort(arr);
+//        System.out.println(Arrays.binarySearch(arr, new Integer(5)));
+
+        /**
+         * 需求: Student(name,age,score);
+         * 定义学生数组
+         * 往学生数组中添加3 个学生Student(zhangsan,10,100) ,(lisi,10,90),(wangwu,10,91)
+         * 王五在班级排第几名
+         */
+        Student[] students = {
+                new Student("zhangsan",10,100.0),
+                new Student("lisi",10,90.0),
+                new Student("wangwu",10,91.0)
+        };
+        // 进行排序,按照成绩进行降序排序
+        Arrays.sort(students);
+        // 在进行查找
+        System.out.println(Arrays.binarySearch(students, new Student("wangwu", 10, 91.0)));
+
+
+
+    }
+}

+ 16 - 0
java-base-project10/day20/src/com/sf/_02_arrays/_03_fill/Test.java

@@ -0,0 +1,16 @@
+package com.sf._02_arrays._03_fill;
+
+import java.util.Arrays;
+
+public class Test {
+    public static void main(String[] args) {
+        /**
+         * 创建数组 长度为6
+         * 通过fill 把数组当中元素内容都填充成5
+         */
+        Integer[] arr = new Integer[6];
+        System.out.println(Arrays.toString(arr));
+        Arrays.fill(arr,5);
+        System.out.println(Arrays.toString(arr));
+    }
+}

+ 66 - 0
java-base-project10/day20/src/com/sf/_02_arrays/_04_copy/Test.java

@@ -0,0 +1,66 @@
+package com.sf._02_arrays._04_copy;
+
+import java.util.Arrays;
+
+public class Test {
+
+    /**
+     * 复制数组
+     * copyOf(arr,newLength);
+     * @param args
+     */
+    public static void main(String[] args) {
+        /**
+         * 定义出来一个数组[1,2,3,4,5,6,7]
+         * 把内容赋值到新的数组中  新的数组的长度为8
+         *
+         * 1 创建创建出来一个长度为5数组 Integer[] arr
+         * 2 定义一个方法可以往数组当中添加元素内容(arr,addEle)
+         * 3 最开是内容[null,null,null,null,null]
+         *   第一次添加1  [1,null,null,null,null]
+         *   当最后一次添加完[1,2,3,4,5]
+         *
+         * 4 当数组已经存满, 这个时候就需要把数组的内容拷贝到一个新的数组中, 新的数组的长度是老的数组长度2倍
+         *   [1,2,3,4,5,null,null,null,null,null]
+         */
+        Integer[] arr = new Integer[5];
+        arr = add(arr,1);
+        System.out.println(Arrays.toString(arr));
+        arr = add(arr,2);
+        System.out.println(Arrays.toString(arr));
+        arr = add(arr,3);
+        System.out.println(Arrays.toString(arr));
+        arr = add(arr,4);
+        System.out.println(Arrays.toString(arr));
+        arr = add(arr,5);
+        System.out.println(Arrays.toString(arr));
+        arr = add(arr,6);
+        System.out.println(Arrays.toString(arr));
+
+    }
+    public static Integer[]  add(Integer[] arr,Integer ele){
+        int count = 0;
+        for (int i = 0; i < arr.length; i++) {
+            Integer e = arr[i];
+            if(e == null){
+                arr[i] = ele;
+                break;
+            }else{
+                count++;
+            }
+        }
+        if(count == arr.length){
+            Integer[] newArr = Arrays.copyOf(arr, arr.length * 2);
+            for (int i = 0; i < newArr.length; i++) {
+                Integer e1 = newArr[i];
+                if(e1 == null){
+                    System.out.println(i);
+                    newArr[i] = ele;
+                    break;
+                }
+            }
+            return newArr;
+        }
+        return  arr;
+    }
+}

+ 50 - 0
java-base-project10/day20/src/com/sf/_02_arrays/_04_copy/Test1.java

@@ -0,0 +1,50 @@
+ package com.sf._02_arrays._04_copy;
+
+ import java.util.Arrays;
+
+ public class Test1 {
+    public static void main(String[] args) {
+        //定义一数组长度为5
+        Integer[] arr = new Integer[5];
+        //调用方法添加元素
+        arr = addEle(arr,1);
+        System.out.println(Arrays.toString(arr));
+        arr = addEle(arr,2);
+        System.out.println(Arrays.toString(arr));
+        arr = addEle(arr,3);
+        System.out.println(Arrays.toString(arr));
+        arr = addEle(arr,4);
+        System.out.println(Arrays.toString(arr));
+        arr = addEle(arr,5);
+        System.out.println(Arrays.toString(arr));
+        arr = addEle(arr,6);
+        System.out.println(Arrays.toString(arr));
+
+    }
+
+    public static Integer[] addEle(Integer[] arr,Integer addEle){
+        // 1 定义不为空数量 用作后续判断是否需要扩容依据
+        Integer notNullCount = 0;
+        // 2 遍历数组拿到每一个元素
+        for (int i = 0; i < arr.length; i++) {
+            Integer ele = arr[i];
+            // 3 如果元素的内容为null , 把内容设置对应索引位置中
+            if(ele == null){
+                arr[i] = addEle;
+                break;
+            }else{
+                // 4 如果不为null, 就让notNullCount ++
+                notNullCount++;
+            }
+        }
+        // 5 如果notNullCount == 数组长度说明数组已经满了
+        if(notNullCount == arr.length){
+            // 6 调用Arrays.copyOf 方法进行扩容
+            Integer[] newArr = Arrays.copyOf(arr, arr.length * 2);
+            // 7 复制以后把要添加元素设置到新数组中
+            newArr[arr.length] = addEle;
+            return newArr;
+        }
+        return arr;
+    }
+}

+ 20 - 0
java-base-project10/day20/src/com/sf/_02_arrays/_05_equlas/Test.java

@@ -0,0 +1,20 @@
+package com.sf._02_arrays._05_equlas;
+
+import java.util.Arrays;
+
+public class Test {
+    public static void main(String[] args) {
+        /**
+         * Arrays.equals(数组1,数组2)
+         * Arrays.toString(数组)
+         * 数组比较
+         */
+        Integer[] arr = {1,2,3,4,5};
+        Integer[] arr1 = {2,1,3,4,5};
+        Integer[] arr2= {1,2,3,4,5};
+        System.out.println(Arrays.equals(arr,arr1));
+        System.out.println(Arrays.equals(arr,arr2));
+
+        System.out.println(Arrays.toString(arr));
+    }
+}

+ 91 - 0
java-base-project10/day20/src/com/sf/_02_arrays/_06_array_convert_list/Student.java

@@ -0,0 +1,91 @@
+package com.sf._02_arrays._06_array_convert_list;
+
+public class Student implements Comparable<Student>{
+    private Long id;
+    private String name;
+    private Integer age;
+    private Double score;
+
+    public Student() {
+    }
+
+    public Student(Long id, String name, Integer age, Double score) {
+        this.id = id;
+        this.name = name;
+        this.age = age;
+        this.score = score;
+    }
+
+    /**
+     * 获取
+     * @return id
+     */
+    public Long getId() {
+        return id;
+    }
+
+    /**
+     * 设置
+     * @param id
+     */
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    /**
+     * 获取
+     * @return name
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * 设置
+     * @param name
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
+     * 获取
+     * @return age
+     */
+    public Integer getAge() {
+        return age;
+    }
+
+    /**
+     * 设置
+     * @param age
+     */
+    public void setAge(Integer age) {
+        this.age = age;
+    }
+
+    /**
+     * 获取
+     * @return score
+     */
+    public Double getScore() {
+        return score;
+    }
+
+    /**
+     * 设置
+     * @param score
+     */
+    public void setScore(Double score) {
+        this.score = score;
+    }
+
+    public String toString() {
+        return "Student{id = " + id + ", name = " + name + ", age = " + age + ", score = " + score + "}";
+    }
+
+    @Override
+    public int compareTo(Student o) {
+        return (int) (this.score - o.getScore());
+    }
+}

+ 22 - 0
java-base-project10/day20/src/com/sf/_02_arrays/_06_array_convert_list/Test.java

@@ -0,0 +1,22 @@
+package com.sf._02_arrays._06_array_convert_list;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class Test {
+    public static void main(String[] args) {
+        /**
+         * List集合 = Arrays.asList(数组)
+         * 数组转集合
+         *
+         * Integer arr = {1,2,3,4,5};
+         * 转成List 集合
+         *
+         *
+         */
+        Integer[] arr = {1,2,3,4,5};
+        List<Integer> list =  Arrays.asList(arr);
+        System.out.println(list);
+
+    }
+}

+ 55 - 0
java-base-project10/day20/src/com/sf/_02_arrays/_06_array_convert_list/Test1.java

@@ -0,0 +1,55 @@
+package com.sf._02_arrays._06_array_convert_list;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+public class Test1 {
+    /**
+     * Student(id,name,age,score)
+     * Student[] student = {3个学生}
+     *
+     * 后续会有的新同学不断进入到班级中 不断往数组中添加元素为了后续更方便往数组中添加元素
+     * 把数组转成集合, 后续在调用集合add 方法添加2 个学生
+     *
+     * 需求:
+     * 1 调用一个initStudents方法提供一个学生的数组信息里面有4个学生
+     *   往里面在添加2个学生
+     * 2 提供方法添加学生方法(数组,添加元素)
+     *  在方法中需要将数组转成集合
+     *  把元素添加到集合中
+     * 3 把集合转回数组 list.toArray();
+     * 4想要知道班级的最高分和最低分排序Arrays.sort();
+     */
+    public static void main(String[] args) {
+        // 1 数组初始化
+        Student[] students = initStudents();
+        // 2 添加学生
+        List<Student> list= addStudent(students,new Student(5L,"fanjialong",10,100.0));
+        // 3 没有顺序集合
+        Collections.sort(list);
+        System.out.println(list);
+    }
+    /**
+     * 往数组中添加元素
+     */
+    public static List<Student>  addStudent(Student[] students,Student student){
+        // 1 把数组转成arrayList  . add 方法很方便操作数组
+        List<Student> list = new ArrayList<>( Arrays.asList(students));
+        list.add(student);
+        return list;
+    }
+    /**
+     * 学生数组信息初始化
+     */
+    public static Student[] initStudents(){
+        Student[] students = {
+                new Student(1L,"zhangsan",10,90.0),
+                new Student(2L,"wangwu",10,60.0),
+                new Student(3L,"zhaoliu",10,70.0),
+                new Student(4L,"lisi",10,77.0)
+        };
+        return students;
+    }
+}

+ 73 - 0
java-base-project10/day20/src/com/sf/_03_collections/Student.java

@@ -0,0 +1,73 @@
+package com.sf._03_collections;
+
+public class Student implements Comparable<Student>{
+    private String name;
+    private int age;
+    private double score;
+
+    public Student() {
+    }
+
+    public Student(String name, int age, double score) {
+        this.name = name;
+        this.age = age;
+        this.score = score;
+    }
+
+    /**
+     * 获取
+     * @return name
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * 设置
+     * @param name
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
+     * 获取
+     * @return age
+     */
+    public int getAge() {
+        return age;
+    }
+
+    /**
+     * 设置
+     * @param age
+     */
+    public void setAge(int age) {
+        this.age = age;
+    }
+
+    /**
+     * 获取
+     * @return score
+     */
+    public double getScore() {
+        return score;
+    }
+
+    /**
+     * 设置
+     * @param score
+     */
+    public void setScore(double score) {
+        this.score = score;
+    }
+
+    public String toString() {
+        return "Student{name = " + name + ", age = " + age + ", score = " + score + "}";
+    }
+
+    @Override
+    public int compareTo(Student o) {
+        return (int) (this.getScore() - o.getScore());
+    }
+}

+ 49 - 0
java-base-project10/day20/src/com/sf/_03_collections/Test.java

@@ -0,0 +1,49 @@
+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<Integer> 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<Student> 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));
+    }
+}

+ 39 - 0
java-base-project10/day20/src/com/sf/_03_collections/Test1.java

@@ -0,0 +1,39 @@
+package com.sf._03_collections;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Scanner;
+
+public class Test1 {
+    /**
+     * List<Double> 存储评委打分的分数
+     *
+     * Scanner 在控制台进行键盘录入  录入5个分数
+     *
+     * 去掉最大值 和最小值
+     * 求平均分就是这个选手最终得分
+     */
+    public static void main(String[] args) {
+        Scanner scanner = new Scanner(System.in);
+        List<Double> list = new ArrayList<>();
+        for (int i = 0; i <= 4; i++) {
+            System.out.println("请第"+ (i+1)+"评委打分");
+            double score = scanner.nextDouble();
+            list.add(score);
+        }
+        // 求最低分
+        Double minScore = Collections.min(list);
+        // 求最高分
+        Double maxScore = Collections.max(list);
+
+        list.remove(minScore);
+        list.remove(maxScore);
+
+        Double totalScore = 0.0;
+        for (Double aDouble : list) {
+            totalScore += aDouble;
+        }
+        System.out.println("评分为:"+ totalScore/list.size());
+    }
+}

+ 35 - 0
java-base-project10/day20/src/com/sf/_03_collections/Test2.java

@@ -0,0 +1,35 @@
+package com.sf._03_collections;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+public class Test2 {
+    public static void main(String[] args) {
+        /**
+         * 替换api
+         * replaceAll(list,oldValue,newValue)
+         * List = {1,2,3,3,4,5}
+         * 把集合当中3 替换成 30
+         */
+        List<Integer> list = new ArrayList<>(Arrays.asList(1,2,3,3,4,5));
+        System.out.println(list);
+        Collections.replaceAll(list,3,30);
+        System.out.println(list);
+
+
+        /**
+         * 反转集合reverse()
+         */
+        Collections.reverse(list);
+        System.out.println(list);
+
+        /**
+         * shuff():
+         * 打乱顺序
+         */
+        Collections.shuffle(list);
+        System.out.println(list);
+    }
+}

+ 59 - 0
java-base-project10/day20/src/com/sf/_03_collections/Test3.java

@@ -0,0 +1,59 @@
+package com.sf._03_collections;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+public class Test3 {
+
+    /**
+     * 创建List<Student> ,往出5个元素
+     * Student name age score
+     *
+     * 先进行打乱顺序,抽取前3名同学
+     * 看三个同学的成绩从小到大如何排序的
+     * 看三个同学成绩从大道小如何进行排序的
+     *
+     * 把成绩最高同学替换成你自己
+     *
+     *
+     */
+    public static void main(String[] args) {
+        List<Student> students = new ArrayList<>(Arrays.asList(
+                new Student("zhangsan",10,90),
+                new Student("lisi",10,91),
+                new Student("wangwu",10,80),
+                new Student("zhaoliu",10,97),
+                new Student("xiaoli",10,60)
+        ));
+        // 打乱顺序
+        Collections.shuffle(students);
+        // 抽查3名同学
+        List<Student> randomStus = new ArrayList<>();
+        // 添加到集合中
+        for (int i = 0; i <=2; i++) {
+            randomStus.add(students.get(i));
+        }
+        // 看集合进行升序排序
+        Collections.sort(randomStus);
+        System.out.println("升序排名-------------");
+        for (Student stus : randomStus) {
+            System.out.println(stus);
+        }
+        System.out.println("---------------");
+        System.out.println("降序排名");
+        Collections.reverse(randomStus);
+        for (Student stus : randomStus) {
+            System.out.println(stus);
+        }
+        System.out.println("------------------");
+        // 要把最高分替换成你自己
+        Student maxScoreStu = randomStus.get(0);
+        Collections.replaceAll(randomStus,maxScoreStu,new Student("fanjialong",18,100));
+        for (Student stus : randomStus) {
+            System.out.println(stus);
+        }
+
+    }
+}