Java 导航ArrayList

Java 导航ArrayList,java,arraylist,Java,Arraylist,我在java上实现QM方法时遇到了一个问题 我在导航2D ArrayList时遇到问题。我在代码中的目标是让ArrayList中的第一个元素成为地址,每当另一个二进制文件配对时,我将找到该地址并添加配对二进制文件的地址 在查找2D数组中第一个元素的索引时,是否有任何方法可以使用indexOf函数 例如。 我的2D ArrayList命名表为 [4][3][7];[7][4];[8][3];[9]; 我想在[4]所在的行中添加int 5。所以我的代码是table.get(table.indexOf

我在java上实现QM方法时遇到了一个问题

我在导航2D ArrayList时遇到问题。我在代码中的目标是让ArrayList中的第一个元素成为地址,每当另一个二进制文件配对时,我将找到该地址并添加配对二进制文件的地址

在查找2D数组中第一个元素的索引时,是否有任何方法可以使用indexOf函数

例如。 我的2D ArrayList命名表为 [4][3][7];[7][4];[8][3];[9];

我想在[4]所在的行中添加int 5。所以我的代码是table.get(table.indexOf(4)).add(5),但它一直说索引是-1。请帮助谢谢

< P> >所以考虑……/P>
ArrayList<ArrayList<Integer>> myList = new ArrayList<ArrayList<Integer>>();

// populate list

Integer index = myList.indexOf(4);

// index is -1 because 4 is not of type: ArrayList<Integer>
ArrayList myList=new ArrayList();
//填充列表
整数索引=myList.indexOf(4);
//索引为-1,因为4不是类型:ArrayList

如果需要基于整数索引添加数组值,我会考虑切换到不同的容器类型,例如:

HashMap<Integer, ArrayList<Integer>>
HashMap
另一种选择是不使用indexOf。。。而是编写自己的函数来循环0到MyList.siz()查找MyList.GET(RooCindex).GET(0)=地址,然后返回外部AARAYLIST索引,在那里找到

,所以考虑……/P>

ArrayList<ArrayList<Integer>> myList = new ArrayList<ArrayList<Integer>>();

// populate list

Integer index = myList.indexOf(4);

// index is -1 because 4 is not of type: ArrayList<Integer>
ArrayList myList=new ArrayList();
//填充列表
整数索引=myList.indexOf(4);
//索引为-1,因为4不是类型:ArrayList

如果需要基于整数索引添加数组值,我会考虑切换到不同的容器类型,例如:

HashMap<Integer, ArrayList<Integer>>
HashMap
另一种选择是不使用indexOf。。。而是编写自己的函数,通过0循环到myList.size(),查找myList.get(loopIndex.get(0)=要找到的地址,然后返回找到它的外部ArrayList索引