由于某种原因,它说我的函数没有返回任何内容。但我正在写:
return (outputList);
...为了返回arrayList。我缺少返回声明。
这是我的其余代码:
public static ArrayList<Integer> duplicatesRemoval(int [] inputList){
ArrayList<Integer> outputList = new ArrayList<>();
int length = inputList.length;
int i = 0;
while(i < length){
int nextElement = inputList[i];
int lengthOut = outputList.size();
int j=0;
boolean found = false;
while (j <= lengthOut && found){
int outputElement = outputList.get(j);
if( nextElement == outputElement){
found = true;
}
j++;
}
if(!found){
outputList.add(nextElement);
i++;
}
return(outputList);
}
}
最佳答案
您的 return 语句位于 while 循环内,因此可能永远不会到达(如果 inputList
是一个空数组)。
关于java - 返回 arrayList 时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33543379/