标签:The style uem com pac turn color vat over
import java.util.ArrayList;
import java.util.List;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import java.util.*;
import java.util.stream.Collectors;
import static java.util.Comparator.comparing;
import static java.util.Comparator.comparingLong;
import static java.util.stream.Collectors.collectingAndThen;
import static java.util.stream.Collectors.toCollection;
1 public static void main(String[] args) { 2 Milk milk0=new Milk(0,"123456"); 3 Milk milk1=new Milk(1,"123476"); 4 Milk milk2=new Milk(0,"876433"); 5 List<Milk> list=new ArrayList<>(); 6 list.add(milk0); 7 list.add(milk1); 8 list.add(milk2); 9 //去重 10 List<Milk> uniqueMilk = list.stream().collect( 11 collectingAndThen( 12 toCollection(() -> new TreeSet<>(comparing(n->n.getKey()))),ArrayList::new) 13 ); 14 15 for (Milk m:uniqueMilk) { 16 System.out.println(m.toString()); 17 } 18 19 }
public class Milk { private Integer key; private String value; public Milk(Integer key, String value) { this.key = key; this.value = value; } public Integer getKey() { return key; } public void setKey(Integer key) { this.key = key; } public String getValue() { return value; } public void setValue(String value) { this.value = value; } @Override public String toString() { return "Milk{" + "key=" + key + ", value=‘" + value + ‘\‘‘ + ‘}‘; } }
标签:The style uem com pac turn color vat over
原文地址:https://www.cnblogs.com/qq1141100952com/p/11197120.html