gstackoverflow gstackoverflow - 7 months ago 39
Java Question

How can I find out the size of a java.util.List if the actual size is greater than the Integer.MAX_VALUE?

As I understood

does not have size restrictions. As I understand, the size() method:

Returns the number of elements in this list. If this list contains
more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Therefore I have following question:

If my
has a size that is larger than the
, is there a way to determine the exact size?

nos nos

You would need to count them yourself, using a bigger data type.

long realSize;

if (myList.size() < Integer.MAX_VALUE) {
    realSize = myList.size();
} else {
    realSize = Integer.MAX_VALUE;
    ListIterator<Foo> iter = myList.listIterator(Integer.MAX_VALUE);
    while (iter.hasNext()) {