Skip to main content
added 99 characters in body
Source Link

From JavaDoc:

indexOf() - Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.

so if your list is rotated (finger != 0) then you can't iterate in indexOf / lastIndexOf / remove methods from 0 to size()-1. You should use this rotated iteration, because this "first occurrence" might be somwhere else in the list if duplicated elements occurs.

Example:

if initial list is:

3, 2, 1, 3

indexOf(3) returs 0

but if you rotate list (by 1?)

2, 1, 3, 3

then your indexOf(3) still returns 0, but it should 2.

To avoid this error in future, prepare better test cases - at least one with duplicated values.

From JavaDoc:

indexOf() - Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.

so if your list is rotated (finger != 0) then you can't iterate in indexOf / lastIndexOf / remove methods from 0 to size()-1. You should use this rotated iteration, because this "first occurrence" might be somwhere else in the list if duplicated elements occurs.

Example:

if initial list is:

3, 2, 1, 3

indexOf(3) returs 0

but if you rotate list (by 1?)

2, 1, 3, 3

then your indexOf(3) still returns 0, but it should 2.

From JavaDoc:

indexOf() - Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.

so if your list is rotated (finger != 0) then you can't iterate in indexOf / lastIndexOf / remove methods from 0 to size()-1. You should use this rotated iteration, because this "first occurrence" might be somwhere else in the list if duplicated elements occurs.

Example:

if initial list is:

3, 2, 1, 3

indexOf(3) returs 0

but if you rotate list (by 1?)

2, 1, 3, 3

then your indexOf(3) still returns 0, but it should 2.

To avoid this error in future, prepare better test cases - at least one with duplicated values.

Source Link

From JavaDoc:

indexOf() - Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.

so if your list is rotated (finger != 0) then you can't iterate in indexOf / lastIndexOf / remove methods from 0 to size()-1. You should use this rotated iteration, because this "first occurrence" might be somwhere else in the list if duplicated elements occurs.

Example:

if initial list is:

3, 2, 1, 3

indexOf(3) returs 0

but if you rotate list (by 1?)

2, 1, 3, 3

then your indexOf(3) still returns 0, but it should 2.