我有两个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);
}