1
ArrayList<ArrayList<Integer>> wordIndex = new ArrayList<ArrayList<Integer>>(Collections.<ArrayList<Integer>>nCopies(initWord.length(), null)); 

// Populate it.

Iterator<ArrayList<Integer>> iterWordIndex = new Iterator<ArrayList<Integer>>(); 

Why can't I do this?

 Cannot instantiate the type Iterator<ArrayList<Integer>>

2 Answers 2

3

You cannot instantiate an Iterator because Iterator is an interface. You can only instantiate concrete classes. In this case, let the ArrayList generate one for you:

Iterator<ArrayList<Integer>> iterWordIndex = wordIndex.iterator();
Sign up to request clarification or add additional context in comments.

Comments

3

Because Iterator is an interface. You can't create an instance of it. You need to create an instance of a concrete class that implements that interface (but most of the time, you just get a reference from an existing collection).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.