To further clarify Nikolai's correct answer: you are trying to create a new object of class list . So you just want to call list.iterator() (which, somewhere inside it, does a new Iterator or something like that and returns it to you).
Since you are explicitly using Java 5 or higher, a better way might be instead to do
public <T> LinkedList<T> sort(LinkedList<T> list){ Iterator<T> iter = new list.iterator(); while (iter.hasNext()){ T t = iter.next(); ... } }
instead of this:
public <T> LinkedList<T> sort(LinkedList<T> list){ for (T t : list){ ... } }
Better yet, do not write this method at all and use instead
Collections.sort(list);
source share