It took a week to refactoring the system's most important section of the printing logic of the code, clear the various types of call relations, proud of the occasion, the test told code data abnormal, spent 5 hours of testing, and finally found the problem, using the wrong ArrayList AddAll method, Below is an enumeration of the add and AddAll methods.
ArrayList is a variable-length array, inherits the Abstractlist class, implements all the list interfaces, and implements the Randomaccess, Cloneable, and serializable interfaces.
Add source code:
Public boolean Add (E e) {
Ensurecapacityinternal (size + 1);
elementdata[size++] = e;
return true;
}
AddAll Source code:
Insert the data in collection C into the ArrayList
public boolean addall (collection<? extends e> c) {
Object[] A = C.toarray ();
int numnew = A.length;
Ensurecapacityinternal (size + numnew); Increments Modcount
System.arraycopy (A, 0, elementdata, size, numnew);
Size + = Numnew;
return numnew!= 0;
}
Inserts data from collection C into the ArrayList at the specified location
public boolean addall (int index, COLLECTION<? extends e> c) {
Rangecheckforadd (index);
Object[] A = C.toarray ();
int numnew = A.length;
Ensurecapacityinternal (size + numnew); Increments Modcount
int nummoved = Size-index;
if (nummoved > 0)
System.arraycopy (Elementdata, index, elementdata, index + numnew,
nummoved);
System.arraycopy (A, 0, Elementdata, index, numnew);
Size + = Numnew;
return numnew!= 0;
}
As you can see, add is storing the incoming parameter as an item in the current list, even if you pass in a list that will only add 1 elements to the other current list, and AddAll is passing in a list that adds all the elements in the list to the current list. That is, the number of elements currently added to the list is the size of the incoming list.