-4

The list declaration:

private List<SharedData> pairList = new ArrayList<>();

and somewhere in the code I'm trying to run a for loop on this List:

for(pairList.iterator().hasNext()) {
        do something;
    }

but, I receive an error:

 Multiple markers at this line

    - Syntax error on tokens, EnhancedForStatementHeaderInit expected 
     instead
    - Syntax error, insert "; ; ) Statement" to complete ForStatement"

That's not so clear for me. Why do I need to add ";;"? I'm also not sure it will run correctly.

Draken
  • 3,134
  • 13
  • 34
  • 54
mibo6700
  • 123
  • 1
  • 2
  • 9

2 Answers2

1

You are looking for the while loop - not for.

0

You should use while loop not for loop because hasNext()returns a boolean.

Bacem
  • 181
  • 1
  • 10