{"id":1435,"date":"2022-11-03T23:03:57","date_gmt":"2022-11-03T15:03:57","guid":{"rendered":"https:\/\/qaqaq.top\/?p=1435"},"modified":"2022-11-27T12:39:44","modified_gmt":"2022-11-27T04:39:44","slug":"stream-api%e7%9a%84%e6%a6%82%e8%bf%b0%e3%80%81stream%e7%9a%84%e5%ae%9e%e4%be%8b%e5%8c%96%e3%80%81stream%e7%9a%84%e4%b8%ad%e9%97%b4%e6%93%8d%e4%bd%9c%ef%bc%9a%e7%ad%9b%e9%80%89%e4%b8%8e%e5%88%87","status":"publish","type":"post","link":"https:\/\/qaqaq.top\/?p=1435","title":{"rendered":"Stream API\u7684\u6982\u8ff0\u3001Stream\u7684\u5b9e\u4f8b\u5316\u3001Stream\u7684\u4e2d\u95f4\u64cd\u4f5c\uff1a\u7b5b\u9009\u4e0e\u5207\u7247\u3001Stream\u7684\u4e2d\u95f4\u64cd\u4f5c\uff1a\u6620\u5c04\u3001Stream\u7684\u4e2d\u95f4\u64cd\u4f5c\uff1a\u6392\u5e8f\u3001Stream\u7684\u7ec8\u6b62\u64cd\u4f5c\uff1a\u5339\u914d\u4e0e\u67e5\u627e\u3001Stream\u7684\u7ec8\u6b62\u64cd\u4f5c\uff1a\u5f52\u7ea6\u3001Stream\u7684\u7ec8\u6b62\u64cd\u4f5c\uff1a\u6536\u96c6"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>package top.qaqaq.java.P677;\n\nimport org.junit.jupiter.api.Test;\n\nimport java.util.Arrays;\nimport java.util.List;\nimport java.util.stream.IntStream;\nimport java.util.stream.Stream;\n\n\/**\n * 1. Stream\u5173\u6ce8\u7684\u662f\u5bf9\u6570\u636e\u7684\u8fd0\u7b97\uff0c\u4e0eCPU\u6253\u4ea4\u9053\n *      \u96c6\u5408\u5173\u6ce8\u7684\u662f\u6570\u636e\u7684\u5b58\u50a8\uff0c\u4e0e\u5185\u5b58\u6253\u4ea4\u9053\n *\n * 2.\n * \u2460Stream \u81ea\u5df1\u4e0d\u4f1a\u5b58\u50a8\u5143\u7d20\u3002\n * \u2461Stream \u4e0d\u4f1a\u6539\u53d8\u6e90\u5bf9\u8c61\u3002\u76f8\u53cd\uff0c\u4ed6\u4eec\u4f1a\u8fd4\u56de\u4e00\u4e2a\u6301\u6709\u7ed3\u679c\u7684\u65b0Stream\u3002\n * \u2462Stream \u64cd\u4f5c\u662f\u5ef6\u8fdf\u6267\u884c\u7684\u3002\u8fd9\u610f\u5473\u7740\u4ed6\u4eec\u4f1a\u7b49\u5230\u9700\u8981\u7ed3\u679c\u7684\u65f6\u5019\u624d\u6267\u884c\u3002\n *\n * 3. Stream \u6267\u884c\u6d41\u7a0b\n * \u2460 Stream\u7684\u5b9e\u4f8b\u5316\n * \u2461 \u4e00\u7cfb\u5217\u7684\u4e2d\u95f4\u64cd\u4f5c\uff08\u8fc7\u6ee4\u3001\u6620\u5c04\u3001...\uff09\n * \u2462 \u7ec8\u6b62\u64cd\u4f5c\n *\n * 4. \u8bf4\u660e\n * 4.1 \u4e00\u4e2a\u4e2d\u95f4\u64cd\u4f5c\u94fe\uff0c\u5bf9\u6570\u636e\u6e90\u7684\u6570\u636e\u8fdb\u884c\u5904\u7406\n * 4.2 \u4e00\u65e6\u6267\u884c\u7ec8\u6b62\u64cd\u4f5c\uff0c\u5c31\u6267\u884c\u4e2d\u95f4\u64cd\u4f5c\u94fe\uff0c\u5e76\u4ea7\u751f\u7ed3\u679c\u3002\u4e4b\u540e\uff0c\u4e0d\u4f1a\u518d\u88ab\u4f7f\u7528\n *\n *  \u6d4b\u8bd5Stream\u7684\u5b9e\u4f8b\u5316\n *\n *\n * @author RichieZhang\n * @create 2022-11-03 \u4e0b\u5348 8:18\n *\/\npublic class StreamAPITest {\n\n    \/\/\u521b\u5efaStream\u65b9\u5f0f\u4e00\uff1a\u901a\u8fc7\u96c6\u5408\n    @Test\n    public void test1(){\n        List&lt;Employee&gt; employees = EmployeeData.getEmployees();\n\/\/        default Stream&lt;E&gt; stream() : \u8fd4\u56de\u4e00\u4e2a\u987a\u5e8f\u6d41\n        Stream&lt;Employee&gt; stream = employees.stream();\n\n\/\/        default Stream&lt;E&gt; parallelStream() : \u8fd4\u56de\u4e00\u4e2a\u5e76\u884c\u6d41\n        Stream&lt;Employee&gt; parallelStream = employees.parallelStream();\n\n    }\n\n    \/\/\u521b\u5efa Stream\u65b9\u5f0f\u4e8c\uff1a\u901a\u8fc7\u6570\u7ec4\n    @Test\n    public void test2(){\n        int&#91;] arr = new int&#91;]{1,2,3,4,5,6};\n        \/\/\u8c03\u7528Arrays\u7c7b\u7684static &lt;T&gt; Stream&lt;T&gt; stream(T&#91;] array): \u8fd4\u56de\u4e00\u4e2a\u6d41\n        IntStream stream = Arrays.stream(arr);\n\n        Employee e1 = new Employee(1001,\"Tom\");\n        Employee e2 = new Employee(1002,\"Jerry\");\n        Employee&#91;] arr1 = new Employee&#91;]{e1,e2};\n        Stream&lt;Employee&gt; stream1 = Arrays.stream(arr1);\n\n    }\n\n    \/\/\u521b\u5efa Stream\u65b9\u5f0f\u4e09\uff1a\u901a\u8fc7Stream\u7684of()\n    @Test\n    public void test3(){\n        Stream&lt;Integer&gt; stream = Stream.of(1, 2, 3, 4, 5, 6);\n\n    }\n\n    \/\/\u521b\u5efa Stream\u65b9\u5f0f\u56db\uff1a\u521b\u5efa\u65e0\u9650\u6d41\n    @Test\n    public void test4(){\n\n\/\/        \u8fed\u4ee3\n\/\/        public static&lt;T&gt; Stream&lt;T&gt; iterate(final T seed, final UnaryOperator&lt;T&gt; f)\n        \/\/\u904d\u5386\u524d10\u4e2a\u5076\u6570\n        Stream.iterate(0, t -&gt; t + 2).limit(10).forEach(System.out::println);\n\n\/\/        \u751f\u6210\n\/\/        public static&lt;T&gt; Stream&lt;T&gt; generate(Supplier&lt;T&gt; s)\n        Stream.generate(Math::random).limit(10).forEach(System.out::println);;\n    }\n}\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>package top.qaqaq.java.P677;\n\nimport org.junit.jupiter.api.Test;\n\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.List;\nimport java.util.stream.Stream;\n\n\/**\n * @author RichieZhang\n * @create 2022-11-03 \u4e0b\u5348 8:44\n *\/\npublic class StreamAPITest1 {\n\n    \/\/1-\u7b5b\u9009\u4e0e\u5207\u7247\n    @Test\n    public void test1(){\n\/\/        filter(Predicate p)\u2014\u2014\u63a5\u6536 Lambda \uff0c \u4ece\u6d41\u4e2d\u6392\u9664\u67d0\u4e9b\u5143\u7d20\u3002\n        List&lt;Employee&gt; list = EmployeeData.getEmployees();\n        Stream&lt;Employee&gt; stream = list.stream();\n        \/\/\u7ec3\u4e60\uff1a\u67e5\u8be2\u5458\u5de5\u8868\u4e2d\u85aa\u8d44\u5927\u4e8e7000\u7684\u5458\u5de5\u4fe1\u606f\n        stream.filter(e -&gt; e.getSalary() &gt; 7000).forEach(System.out::println);\n\n        System.out.println();\n\n\/\/        limit(n)\u2014\u2014\u622a\u65ad\u6d41\uff0c\u4f7f\u5176\u5143\u7d20\u4e0d\u8d85\u8fc7\u7ed9\u5b9a\u6570\u91cf\u3002\n        list.stream().limit(3).forEach(System.out::println);\n\n        System.out.println();\n\n\/\/        skip(n) \u2014\u2014 \u8df3\u8fc7\u5143\u7d20\uff0c\u8fd4\u56de\u4e00\u4e2a\u6254\u6389\u4e86\u524d n \u4e2a\u5143\u7d20\u7684\u6d41\u3002\u82e5\u6d41\u4e2d\u5143\u7d20\u4e0d\u8db3 n \u4e2a\uff0c\u5219\u8fd4\u56de\u4e00\u4e2a\u7a7a\u6d41\u3002\u4e0e limit(n) \u4e92\u8865\n        list.stream().skip(3).forEach(System.out::println);\n\n        System.out.println();\n\n\/\/        distinct()\u2014\u2014\u7b5b\u9009\uff0c\u901a\u8fc7\u6d41\u6240\u751f\u6210\u5143\u7d20\u7684 hashCode() \u548c equals() \u53bb\u9664\u91cd\u590d\u5143\u7d20\n        list.add(new Employee(1010,\"\u5218\u5f3a\u4e1c\",40,8000));\n        list.add(new Employee(1010,\"\u5218\u5f3a\u4e1c\",41,8000));\n        list.add(new Employee(1010,\"\u5218\u5f3a\u4e1c\",40,8000));\n        list.add(new Employee(1010,\"\u5218\u5f3a\u4e1c\",40,8000));\n        list.add(new Employee(1010,\"\u5218\u5f3a\u4e1c\",40,8000));\n\n\/\/        System.out.println(list);\n\n        list.stream().distinct().forEach(System.out::println);\n    }\n\n    \/\/\u6620\u5c04\n    @Test\n    public void test2(){\n\/\/        map(Function f)\u2014\u2014\u63a5\u6536\u4e00\u4e2a\u51fd\u6570\u4f5c\u4e3a\u53c2\u6570\uff0c\u5c06\u5143\u7d20\u8f6c\u6362\u6210\u5176\u4ed6\u5f62\u5f0f\u6216\u63d0\u53d6\u4fe1\u606f\uff0c\u8be5\u51fd\u6570\u4f1a\u88ab\u5e94\u7528\u5230\u6bcf\u4e2a\u5143\u7d20\u4e0a\uff0c\u5e76\u5c06\u5176\u6620\u5c04\u6210\u4e00\u4e2a\u65b0\u7684\u5143\u7d20\u3002\n        List&lt;String&gt; list = Arrays.asList(\"aa\", \"bb\", \"cc\", \"dd\");\n        list.stream().map(str -&gt; str.toUpperCase()).forEach(System.out::println);\n\n\/\/        \u7ec3\u4e601\uff1a\u83b7\u53d6\u5458\u5de5\u59d3\u540d\u957f\u5ea6\u5927\u4e8e3\u7684\u5458\u5de5\u7684\u59d3\u540d\u3002\n        List&lt;Employee&gt; employees = EmployeeData.getEmployees();\n        Stream&lt;String&gt; nameStream = employees.stream().map(Employee::getName);\n        nameStream.filter(name -&gt; name.length() &gt; 3).forEach(System.out::println);\n\n        System.out.println();\n\n        \/\/\u7ec3\u4e602\uff1a\n        Stream&lt;Stream&lt;Character&gt;&gt; streamStream = list.stream().map(StreamAPITest1::fromStringToStream);\n        streamStream.forEach(s -&gt; {\n            s.forEach(System.out::println);\n        });\n\n        System.out.println();\n\n\/\/        flatMap(Function f)\u2014\u2014\u63a5\u6536\u4e00\u4e2a\u51fd\u6570\u4f5c\u4e3a\u53c2\u6570\uff0c\u5c06\u6d41\u4e2d\u7684\u6bcf\u4e2a\u503c\u90fd\u6362\u6210\u53e6\u4e00\u4e2a\u6d41\uff0c\u7136\u540e\u628a\u6240\u6709\u6d41\u8fde\u63a5\u6210\u4e00\u4e2a\u6d41\u3002\n        Stream&lt;Character&gt; characterStream = list.stream().flatMap(StreamAPITest1::fromStringToStream);\n        characterStream.forEach(System.out::println);\n    }\n\n    \/\/\u5c06\u5b57\u7b26\u4e32\u4e2d\u7684\u591a\u4e2a\u5b57\u7b26\u6784\u6210\u7684\u96c6\u5408\u8f6c\u6362\u4e3a\u5bf9\u5e94\u7684Stream\u7684\u5b9e\u4f8b\n    public static Stream&lt;Character&gt; fromStringToStream(String str){\n        ArrayList&lt;Character&gt; list = new ArrayList&lt;&gt;();\n        for (Character c : str.toCharArray()){\/\/aa\n            list.add(c);\n        }\n        return list.stream();\n    }\n\n    @Test\n    public void test3(){\n        ArrayList list1 = new ArrayList();\n        list1.add(1);\n        list1.add(2);\n        list1.add(3);\n\n        ArrayList list2 = new ArrayList();\n        list2.add(4);\n        list2.add(5);\n        list2.add(6);\n\n        list1.add(list2);\n        list1.addAll(list2);\n        System.out.println(list1);\n    }\n\n    \/\/3-\u6392\u5e8f\n    @Test\n    public void test4(){\n\/\/        sorted()\u2014\u2014\u81ea\u7136\u6392\u5e8f\n        List&lt;Integer&gt; list = Arrays.asList(12,43,65,34,87,0,-98,7);\n        list.stream().sorted().forEach(System.out::println);\n\n        \/\/\u629b\u5f02\u5e38\uff0c\u539f\u56e0: Employee\u6ca1\u6709\u5b9e\u73b0Comparable\u63a5\u53e3\n\/\/        List&lt;Employee&gt; employees = EmployeeData.getEmployees();\n\/\/        employees.stream().sorted().forEach(System.out::println);\n\n\/\/        sorted(Comparator com)\u2014\u2014\u5b9a\u5236\u6392\u5e8f\n        List&lt;Employee&gt; employees = EmployeeData.getEmployees();\n        employees.stream().sorted((e1,e2) -&gt; {\n            int avgValue = Integer.compare(e1.getAge(), e2.getAge());\n            if(avgValue != 0){\n                return avgValue;\n            }else {\n                return -Double.compare(e1.getSalary(),e2.getSalary());\n            }\n        }).forEach(System.out::println);\n    }\n}\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>package top.qaqaq.java.P677;\r\n\r\nimport org.junit.jupiter.api.Test;\r\n\r\nimport java.util.Arrays;\r\nimport java.util.List;\r\nimport java.util.Optional;\r\nimport java.util.Set;\r\nimport java.util.stream.Collectors;\r\nimport java.util.stream.Stream;\r\n\r\n\/**\r\n * @author RichieZhang\r\n * @create 2022-11-03 \u4e0b\u5348 10:09\r\n *\/\r\npublic class StreamAPITest2 {\r\n\r\n    \/\/1-\u5339\u914d\u4e0e\u67e5\u627e\r\n    @Test\r\n    public void test1(){\r\n        List&lt;Employee> employees = EmployeeData.getEmployees();\r\n\r\n\/\/        allMatch(Predicate p)\u2014\u2014\u68c0\u67e5\u662f\u5426\u5339\u914d\u6240\u6709\u5143\u7d20\u3002\r\n\/\/        \u7ec3\u4e60\uff1a\u662f\u5426\u6240\u6709\u7684\u5458\u5de5\u7684\u5e74\u9f84\u90fd\u5927\u4e8e18\r\n        boolean allMatch = employees.stream().allMatch(e -> e.getAge() > 18);\r\n        System.out.println(allMatch);\r\n\r\n\/\/        anyMatch(Predicate p)\u2014\u2014\u68c0\u67e5\u662f\u5426\u81f3\u5c11\u5339\u914d\u4e00\u4e2a\u5143\u7d20\u3002\r\n\/\/        \u7ec3\u4e60\uff1a\u662f\u5426\u5b58\u5728\u5458\u5de5\u7684\u5de5\u8d44\u5927\u4e8e 10000\r\n        boolean anyMatch = employees.stream().anyMatch(e -> e.getSalary() > 10000);\r\n        System.out.println(anyMatch);\r\n\r\n\/\/        noneMatch(Predicate p)\u2014\u2014\u68c0\u67e5\u662f\u5426\u6ca1\u6709\u5339\u914d\u7684\u5143\u7d20\u3002\r\n\/\/        \u7ec3\u4e60\uff1a\u662f\u5426\u5b58\u5728\u5458\u5de5\u59d3\u201c\u96f7\u201d\r\n        boolean noneMatch = employees.stream().noneMatch(e -> e.getName().startsWith(\"\u96f7\"));\r\n        System.out.println(noneMatch);\r\n\/\/        findFirst\u2014\u2014\u8fd4\u56de\u7b2c\u4e00\u4e2a\u5143\u7d20\r\n        Optional&lt;Employee> employee = employees.stream().findFirst();\r\n        System.out.println(employee);\r\n\/\/        findAny\u2014\u2014\u8fd4\u56de\u5f53\u524d\u6d41\u4e2d\u7684\u4efb\u610f\u5143\u7d20\r\n        Optional&lt;Employee> employee1 = employees.parallelStream().findAny();\r\n        System.out.println(employee1);\r\n\r\n    }\r\n\r\n    @Test\r\n    public void test2(){\r\n        List&lt;Employee> employees = EmployeeData.getEmployees();\r\n\/\/        count\u2014\u2014\u8fd4\u56de\u6d41\u4e2d\u5143\u7d20\u7684\u603b\u4e2a\u6570\r\n        long count = employees.stream().filter(e -> e.getSalary() > 5000).count();\r\n        System.out.println(count);\r\n\/\/        max(Comparator c)\u2014\u2014\u8fd4\u56de\u6d41\u4e2d\u6700\u5927\u503c\r\n\/\/        \u7ec3\u4e60\uff1a\u8fd4\u56de\u6700\u9ad8\u7684\u5de5\u8d44\uff1a\r\n        Stream&lt;Double> salaryStream = employees.stream().map(e -> e.getSalary());\r\n        Optional&lt;Double> maxSalary = salaryStream.max(Double::compare);\r\n        System.out.println(maxSalary);\r\n\/\/        min(Comparator c)\u2014\u2014\u8fd4\u56de\u6d41\u4e2d\u6700\u5c0f\u503c\r\n\/\/        \u7ec3\u4e60\uff1a\u8fd4\u56de\u6700\u4f4e\u5de5\u8d44\u7684\u5458\u5de5\r\n        Optional&lt;Employee> employee = employees.stream().min((e1, e2) -> Double.compare(e1.getSalary(), e2.getSalary()));\r\n        System.out.println(employee);\r\n\r\n\r\n\/\/        forEach(Consumer c)\u2014\u2014\u5185\u90e8\u8fed\u4ee3\r\n        employees.stream().forEach(System.out::println);\r\n\r\n        \/\/\u4f7f\u7528\u96c6\u5408\u7684\u904d\u5386\u64cd\u4f5c\r\n        employees.forEach(System.out::println);\r\n    }\r\n\r\n    \/\/2-\u5f52\u7ea6\r\n    @Test\r\n    public void test3(){\r\n\/\/        reduce(T identity, BinaryOperator)\u2014\u2014\u53ef\u4ee5\u5c06\u6d41\u4e2d\u5143\u7d20\u53cd\u590d\u7ed3\u5408\u8d77\u6765\uff0c\u5f97\u5230\u4e00\u4e2a\u503c\u3002\u8fd4\u56de T\r\n\/\/        \u7ec3\u4e601\uff1a\u8ba1\u7b971-10\u7684\u81ea\u7136\u6570\u7684\u548c\r\n        List&lt;Integer> list = Arrays.asList(1,2,3,4,5,6,7,8,9,10);\r\n        Integer sum = list.stream().reduce(0, Integer::sum);\r\n        System.out.println(sum);\r\n\r\n\/\/        reduce(BinaryOperator) \u2014\u2014\u53ef\u4ee5\u5c06\u6d41\u4e2d\u5143\u7d20\u53cd\u590d\u7ed3\u5408\u8d77\u6765\uff0c\u5f97\u5230\u4e00\u4e2a\u503c\u3002\u8fd4\u56de Optional&lt;T>\r\n\/\/        \u7ec3\u4e602\uff1a\u8ba1\u7b97\u516c\u53f8\u6240\u6709\u5458\u5de5\u5de5\u8d44\u7684\u603b\u548c\r\n        List&lt;Employee> employees = EmployeeData.getEmployees();\r\n        Stream&lt;Double> salaryStream = employees.stream().map(Employee::getSalary);\r\n\/\/        Optional&lt;Double> sumMoney = salaryStream.reduce(Double::sum);\r\n        Optional&lt;Double> sumMoney = salaryStream.reduce((d1,d2) -> d1 + d2);\r\n        System.out.println(sumMoney.get());\r\n    }\r\n\r\n    \/\/3-\u6536\u96c6\r\n    @Test\r\n    public void test4(){\r\n\/\/        collect(Collector c)\u2014\u2014\u5c06\u6d41\u8f6c\u6362\u4e3a\u5176\u4ed6\u5f62\u5f0f\u3002\u63a5\u6536\u4e00\u4e2a Collector\u63a5\u53e3\u7684\u5b9e\u73b0\uff0c\u7528\u4e8e\u7ed9Stream\u4e2d\u5143\u7d20\u505a\u6c47\u603b\u7684\u65b9\u6cd5\r\n\/\/        \u7ec3\u4e601\uff1a\u67e5\u627e\u5de5\u8d44\u5927\u4e8e6000\u7684\u5458\u5de5\uff0c\u7ed3\u679c\u8fd4\u56de\u4e3a\u4e00\u4e2aList\u6216Set\r\n\r\n        List&lt;Employee> employees = EmployeeData.getEmployees();\r\n        List&lt;Employee> employeeList = employees.stream().filter(e -> e.getSalary() > 6000).collect(Collectors.toList());\r\n\r\n        employeeList.forEach(System.out::println);\r\n\r\n        System.out.println();\r\n\r\n        Set&lt;Employee> employeeSet = employees.stream().filter(e -> e.getSalary() > 6000).collect(Collectors.toSet());\r\n\r\n        employeeSet.forEach(System.out::println);\r\n    }\r\n}\r\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>package top.qaqaq.java.P677;\n\n\/**\n * @author shkstart \u90ae\u7bb1\uff1ashkstart@126.com\n *\/\npublic class Employee {\n\n\tprivate int id;\n\tprivate String name;\n\tprivate int age;\n\tprivate double salary;\n\n\tpublic int getId() {\n\t\treturn id;\n\t}\n\n\tpublic void setId(int id) {\n\t\tthis.id = id;\n\t}\n\n\tpublic String getName() {\n\t\treturn name;\n\t}\n\n\tpublic void setName(String name) {\n\t\tthis.name = name;\n\t}\n\n\tpublic int getAge() {\n\t\treturn age;\n\t}\n\n\tpublic void setAge(int age) {\n\t\tthis.age = age;\n\t}\n\n\tpublic double getSalary() {\n\t\treturn salary;\n\t}\n\n\tpublic void setSalary(double salary) {\n\t\tthis.salary = salary;\n\t}\n\n\tpublic Employee() {\n\t\tSystem.out.println(\"Employee().....\");\n\t}\n\n\tpublic Employee(int id) {\n\n\t\tthis.id = id;\n\t\tSystem.out.println(\"Employee(int id).....\");\n\t}\n\n\tpublic Employee(int id, String name) {\n\t\tthis.id = id;\n\t\tthis.name = name;\n\t}\n\n\tpublic Employee(int id, String name, int age, double salary) {\n\n\t\tthis.id = id;\n\t\tthis.name = name;\n\t\tthis.age = age;\n\t\tthis.salary = salary;\n\t}\n\n\t@Override\n\tpublic String toString() {\n\t\treturn \"Employee{\" + \"id=\" + id + \", name='\" + name + '\\'' + \", age=\" + age + \", salary=\" + salary + '}';\n\t}\n\n\t@Override\n\tpublic boolean equals(Object o) {\n\t\tif (this == o)\n\t\t\treturn true;\n\t\tif (o == null || getClass() != o.getClass())\n\t\t\treturn false;\n\n\t\tEmployee employee = (Employee) o;\n\n\t\tif (id != employee.id)\n\t\t\treturn false;\n\t\tif (age != employee.age)\n\t\t\treturn false;\n\t\tif (Double.compare(employee.salary, salary) != 0)\n\t\t\treturn false;\n\t\treturn name != null ? name.equals(employee.name) : employee.name == null;\n\t}\n\n\t@Override\n\tpublic int hashCode() {\n\t\tint result;\n\t\tlong temp;\n\t\tresult = id;\n\t\tresult = 31 * result + (name != null ? name.hashCode() : 0);\n\t\tresult = 31 * result + age;\n\t\ttemp = Double.doubleToLongBits(salary);\n\t\tresult = 31 * result + (int) (temp ^ (temp &gt;&gt;&gt; 32));\n\t\treturn result;\n\t}\n}\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>package top.qaqaq.java.P677;\n\nimport java.util.ArrayList;\nimport java.util.List;\n\n\/**\n * \u63d0\u4f9b\u7528\u4e8e\u6d4b\u8bd5\u7684\u6570\u636e\n * \n * @author shkstart \u90ae\u7bb1\uff1ashkstart@126.com\n *\n *\/\npublic class EmployeeData {\n\t\n\tpublic static List&lt;Employee&gt; getEmployees(){\n\t\tList&lt;Employee&gt; list = new ArrayList&lt;&gt;();\n\t\t\n\t\tlist.add(new Employee(1001, \"\u9a6c\u5316\u817e\", 34, 6000.38));\n\t\tlist.add(new Employee(1002, \"\u9a6c\u4e91\", 12, 9876.12));\n\t\tlist.add(new Employee(1003, \"\u5218\u5f3a\u4e1c\", 33, 3000.82));\n\t\tlist.add(new Employee(1004, \"\u96f7\u519b\", 26, 7657.37));\n\t\tlist.add(new Employee(1005, \"\u674e\u5f66\u5b8f\", 65, 5555.32));\n\t\tlist.add(new Employee(1006, \"\u6bd4\u5c14\u76d6\u8328\", 42, 9500.43));\n\t\tlist.add(new Employee(1007, \"\u4efb\u6b63\u975e\", 26, 4333.32));\n\t\tlist.add(new Employee(1008, \"\u624e\u514b\u4f2f\u683c\", 35, 2500.32));\n\t\t\n\t\treturn list;\n\t}\n\t\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[46],"class_list":["post-1435","post","type-post","status-publish","format-standard","hentry","category-java-code","tag-java"],"_links":{"self":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/1435"}],"collection":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1435"}],"version-history":[{"count":2,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/1435\/revisions"}],"predecessor-version":[{"id":1438,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/1435\/revisions\/1438"}],"wp:attachment":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1435"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1435"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1435"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}