java doc for java.util.List#size()
Returns the number of elements in this list. If this list contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.
Research java.util.LinkedList
source code:
public method:
public boolean add(E e) {
addBefore(e, header);
return true;
}
private Entry<E> addBefore(E e, Entry<E> entry) {
Entry<E> newEntry = new Entry<E>(e, entry, entry.previous);
newEntry.previous.next = newEntry;
newEntry.next.previous = newEntry;
size++;
modCount++;
return newEntry;
}
Thus if before adding element size equals Integer.MAX_VALUE
size will become
-Integer.MAX_VALUE-1
method size just returns field value without checks:
public int size() {
return size;
}
What do you think about it?