Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Arraylist按指定顺序搜索2个元素_Java_Arraylist - Fatal编程技术网

Java Arraylist按指定顺序搜索2个元素

Java Arraylist按指定顺序搜索2个元素,java,arraylist,Java,Arraylist,我想做一个代码,可以在arraylist中搜索2个元素。元素的顺序很重要。搜索的元素:adjLists.get(l).get(h),adjLists.get(l).get(h+1) List List=new ArrayList(); 添加(adjLists.get(l.get(h)); add(adjLists.get(l.get(h+1)); 对于(列表阵列列表:调整列表){ while(arrayList.containsAll(列表)){ 集合(arrayList.indexOf(adj

我想做一个代码,可以在arraylist中搜索2个元素。元素的顺序很重要。搜索的元素:
adjLists.get(l).get(h),adjLists.get(l).get(h+1)

List List=new ArrayList();
添加(adjLists.get(l.get(h));
add(adjLists.get(l.get(h+1));
对于(列表阵列列表:调整列表){
while(arrayList.containsAll(列表)){
集合(arrayList.indexOf(adjLists.get(l).get(h+1)+1),1);
}
}

您可以使用传统的for循环:

for (int i = 0; i < list.size()-1; i++) {
    if (list.get(i) == firstVal && list.get(i+1) == secondVal) {
        // Victory!
    }
}
for(int i=0;i
您可以使用Collections.indexofpublist

    int i = Collections.indexOfSubList(list, Arrays.asList(o1, o2));

抱歉,这是一个列表列表,有两个get。我已经试过了,不起作用。
for(intlj=0;lj
此cide与您的cide执行相同的操作,但不起作用,似乎什么都不做。是的,这会导致问题。例如:
int j=Collections.indexofpublist(AdjList,array.asList(AdjList.get(l).get(h),AdjList.get(l).get(h+1))?在那之后我如何搜索呢?如果I==-1,那么搜索失败;否则它是第一个元素的索引,i+1是第二个元素的索引应该使用哪个循环以及如何使用?请给我更多的细节,收藏对我来说是新的。索引?在哪个名单上?我认为识别一个元素需要两个数字。
    int i = Collections.indexOfSubList(list, Arrays.asList(o1, o2));