<分区>
我在 java 中有一个列表列表。
static ArrayList<List> permutationS = new ArrayList<List>();
内部列表是整数的 ArrayList。
List<Integer> innerList = new ArrayList<Integer>();
现在我想选择一个 innerList,如果它包含一个特定的整数。 我怎样才能做到这一点?
<分区>
我在 java 中有一个列表列表。
static ArrayList<List> permutationS = new ArrayList<List>();
内部列表是整数的 ArrayList。
List<Integer> innerList = new ArrayList<Integer>();
现在我想选择一个 innerList,如果它包含一个特定的整数。 我怎样才能做到这一点?
最佳答案
这样做:
List<List<Integer>> permutationS = new ArrayList<>();
// list initialization here
int i = 5; // the Integer you are searching for
for(List<Integer> innerList : permutationS) {
if(innerList.contains(i)) {
// found, do something with innerList
}
}
关于java - 从列表列表中提取列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45037559/