其中有一个ArrayList1和一个包含多个数组的List2。
我希望将arraylist1中的内容与所有数组列表(在List2中)进行比较,并从List2中删除不等于arraylist1的记录。
有几个问题和这个相似,但我不明白。请帮帮忙。
谢谢你,迈克
发布于 2014-04-03 13:33:17
根据您想要实现的方式,迭代:
List<String> yourSingleList = new ArrayList<>();
for (List<String> list : yourListOfLists) {
//remove entries
list.retainAll(yourSingleList);
//or remove matching entities
list.removeAll(yourSingleList);
}
或者使用迭代器进行完全比较:
List<String> yourSingleList = new ArrayList<>();
Iterator<List<String>> lists = yourListOfLists.iterator();
while (lists.hasNext()) {
if (!lists.next().equals(yourSingleList) {
lists.remove();
}
}
发布于 2014-04-03 13:34:55
我想你想要这样的东西:
List<List<String>> listlist = new ArrayList<List<String>>();
List<String> list = new ArrayList<String>();
// some example input here
list.add("A");
list.add("B");
list.add("C");
listlist.add(list);
for (List<String> l : listlist) {
for(String s : l) {
if (list.contains(s)) {
System.out.println(s + " is at position " + list.indexOf(s));
}
}
}
发布于 2014-04-03 13:36:48
请查看>,将其视为二维数组,并将列表A中的每个元素与列表B.get(1)、列表B.get(2)中的每个元素进行比较,等等。
https://stackoverflow.com/questions/22839264
复制相似问题