ArrayList<int[]> queue = new ArrayList<>(); if (isValid(x, y, colorFill, colorBoundary, graphics)){ int[] add = new int[2]; add[0]=x; add[1]=y; queue.add(add); } while (!queue.isEmpty()){ int[] get = queue.get(queue.size()); graphics.putPixel(get[0],get[1],colorFill); queue.remove(queue.size());...}嘿,我从ArrayList queue = new ArrayList ();获取数组时遇到问题。你有什么我犯错的建议? 最佳答案 来自List::get(int index)  返回此列表中指定位置的元素。  抛出:  IndexOutOfBoundsException-如果索引超出范围(索引 = size())在您在下面的行中书写时的问题:queue.get(queue.size());那么它违反了index >= size()条件,因为您正在传递queue.size()传递索引值b / w 0和queue.size() - 1以获取元素。例:int[] get = queue.get(queue.size()-1);关于java - 如何从ArrayList <>获取数组,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58913328/
10-11 22:39
查看更多