import java.util.*;
public class ArrayListTesting 
{
    public static void main(String []args)
    {
        LinkedList<String> list = new LinkedList<String>();
        list.add("apple");
        list.add("pear");
        list.add("tree");
        Iterator <String> iterate = list.iterator();
        System.out.println(iterate.next());
        System.out.println(iterate.previous());
        System.out.println(iterate.next());
        System.out.println(iterate.hasNext());
    }
}

it keep telling me it an error.

Recommended Answers

All 2 Replies

What is the error? What is the output before an exception is thrown?

You may want ListIterator, not Iterator. Iterator does NOT have previous() method.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.