Java collections deduplication

// set of general de-emphasis method List
public List<floorMapper> removethesame(List<floorMapper> list) {
    // Create a temporary set of loaded data deduplication
    List<floorMapper> tempList = new ArrayList<floorMapper>();
    for (floorMapper i : list) {
        if (! tempList.contains (i)) {// determines whether the data is repeated, if there is no data will be loaded into the set of temporary
            tempList.add(i);
        }
    }
    return tempList;
}


// Java, according to the set weight based on an attribute of an object
private static List<floorMapper> removeDuplicateFlight(List<floorMapper> flights) {
    Set<floorMapper> set = new TreeSet<floorMapper>(new Comparator<floorMapper>() {
        @Override
        public int compare(floorMapper o1, floorMapper o2) {
            // string, arranged in ascending order code asicc
            return o1.getFloorid().compareTo(o2.getFloorid());
        }
    });
    set.addAll(flights);
    return new ArrayList<floorMapper>(set);
}

  

Guess you like

Origin www.cnblogs.com/EarlyBridVic/p/12125765.html