我有两个arrayLists分别是readAllNames和另一个是selectedNames。现在我想获取具有unSelectedNames .ex的另一个列表。

List<Name>readAllNames = {"a","b","c","d","e","f","g"};
List<Name>selectedNames = {"a","b"};


我如何从unSelectedNames获取readAllNames {“ c”,“ d”,“ e”,“ f”,“ g”}?

不使用remove()removeAll()

最佳答案

List<String> unread = new ArrayList<String>();
for(String s : readAllNames ){
    if(!selectedNames.contains(s))
        unread.add(s);
}

08-05 18:10