随笔- 659  评论- 206  文章- 4 

比较两个list对象是否相同

public Boolean exist(Container container){
    List<SensorAtom> newSensorList = container.getSensorList();
    List<SensorAtom> oldSensorList = containerSensorService.getSensorList(container.getContainerId());

    if(newSensorList == null && oldSensorList == null){
        return true;
    }
    else if(newSensorList == null || oldSensorList == null){
        return false;
    }
    else if(newSensorList.size() != oldSensorList.size()){
        return false;
    }
    else {
        return newSensorList.stream().allMatch(n -> oldSensorList.contains(n));
    }
}

 

posted on 2017-03-25 20:24  一路前行  阅读(...)  评论(...编辑  收藏