ArrayIndexOutOfBoundsException when using the ArrayList’s iterator [duplicate]

Am I doing that right, as far as iterating through the Arraylist goes?

No: by calling iterator twice in each iteration, you’re getting new iterators all the time.

The easiest way to write this loop is using the for-each construct:

for (String s : arrayList)
    if (s.equals(value))
        // ...

As for

java.lang.ArrayIndexOutOfBoundsException: -1

You just tried to get element number -1 from an array. Counting starts at zero.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)