I have this method that is removing elements from a list,
List<LinkedList<Object>> list = new LinkedList<>();
that removes two elements, returns a list which is then put through a queue names=queue.removePair();
public List removePair() {
List<E> nList = new LinkedList<>();
if (list.isEmpty() == true) {
throw new InsufficientElementsException();
}
if (list.isEmpty() == false) {
Object temp;
for (int i = 0; i < list.size(); i++) {
temp = list.get(i).size();
if (temp.equals(2)) {
nList.add((E) list.get(i));
list.remove(i);
}
}
return nList;
}
return nList;
}
I believe this doesn't work because when I return the Nlist, it's only returning the one declared in the first line? How do I fix this?
Aucun commentaire:
Enregistrer un commentaire