ArrayList<Integer> arr = ArrayList<Integer>( i = 10;i<15;i++10 }
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 10, Size: 554738715)
An out-of-bounds exception is reported when the "10" element is removed from arr.
The reason is:
E remove (1 =? Get (I) =: The minimum index element of o. equals (get (I) (if such an element exists ). If the list contains the specified element, return (or equivalent to this case: if the list is changed due to a call ).
ArrayList<Integer> arr = ArrayList<Integer>( i = 10;i<15;i++ arr.remove((Integer)10);
ArrayList<Integer> arr = ArrayList<Integer>( i = 10;i<15;i++ arrSize =( i = 0;i<arrSize;i++(10 ==
The above Code cannot be executed, and an out-of-bounds exception is reported.
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 4, Size: 454732217)
ArrayList <Integer> arr = ArrayList <Integer> (I = 10; I <15; I ++ 1010101011 "before deletion:" + (I = 0; I <arr. size (); I ++ (10 = "after deletion:" + arr. size ());
Take a closer look at the execution results:
Before deletion: 107
What are the two conditions in the preceding case when arraylist is removed?
The reason is that the size after each remove operation changes, but the iteration base is not dynamically adjusted based on the size after the remove operation, resulting in incomplete cross-border and set traversal.
The correct method is as follows:
ArrayList <Integer> arr = ArrayList <Integer> (I = 10; I <15; I ++ 1010101011 "before deletion:" + (I = 0; I <arr. size (); I ++ (10 = -- "after deletion:" + arr. size ());
After the remove operation, the index location is-1,
Or use an iterator.
ArrayList <Integer> arr = ArrayList <Integer> (I = 10; I <15; I ++ 1010101011 "before deletion:" + <Integer> it = (10 =