In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces java how to filter the same value in list and filter different values of the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, with a certain reference value, I believe that after reading this java how to filter the same value in list and filter different values of the article will have a harvest, let's take a look.
The code is as follows:
Public class People {private String id; private String somethingElse; public People () {} public People (String id, String somethingElse) {this.id = id; this.somethingElse = somethingElse;} public String getId () {return id;} public void setId (String id) {this.id = id;} public String getSomethingElse () {return somethingElse } public void setSomethingElse (String somethingElse) {this.somethingElse = somethingElse;} @ Override public String toString () {return "People {" + "id='" + id +'\'+ ", somethingElse='" + somethingElse +'\'+'}';}}
People entity class and student entity class
People class
Studentpublic class Student {private String id; private String idCard; private String somethingElse; public Student () {} public Student (String id, String idCard, String somethingElse) {this.id = id; this.idCard = idCard; this.somethingElse = somethingElse;} public String getId () {return id;} public void setId (String id) {this.id = id } public String getIdCard () {return idCard;} public void setIdCard (String idCard) {this.idCard = idCard;} public String getSomethingElse () {return somethingElse;} public void setSomethingElse (String somethingElse) {this.somethingElse = somethingElse } @ Override public String toString () {return "Student {" + "id='" + id +'\'+ ", idCard='" + idCard +'\'+ ", somethingElse='" + somethingElse +'\'+'}';}}
Test class
Public static void main (String [] args) throws Exception {/ / initialization data List studentList = new ArrayList () {{add (new Student ("1", "11", "111")); add (new Student (" 2 "," 22nd ")); add (new Student (" 3 "," 33 "," 333 "));}} List peopleList = new ArrayList () {{add (new People ("11", "111")); add (new People (" 222,222 ")); add (new People (" 33 "," 333 "));}} / / get the same field content and convert it to set Set ids = peopleList .stream () .map (People::getId) .fields (Collectors.toSet ()) / / filter duplicates List result = studentList .stream () .filter (e-> ids.contains (e.getIdCard () .filter (Collectors.toList ()); System.out.println (result) / / get the same field content and convert it to set Set ids = peopleList .stream () .map (People::getId) .fields (Collectors.toSet ()) / / filter duplicates List result = studentList .stream () .filter (e->! ids.contains (e.getIdCard () .filter (Collectors.toList ()); System.out.println (result);} this is the end of the article on "how java filters the same values and different values in list". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how java filters the same values and different values in list". If you want to learn more, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.