>>Is it possible to efficiently split a large Vector into smaller sub-Vectors
>>without iterating through it and adding the Objects to the sub-Vectors? If
[quoted text clipped - 3 lines]
>
> java.util.List#subList(int,int)
I tried using ArrayList for this but I get a ClassCastException error at
the following line:
lArray[j] = (ArrayList)lStates.subList(lStart, lEnd);
What can I do to avoid this? I read the docs but cant see anything that
says what to do.
Thanks.
Allan
Virgil Green - 27 May 2005 23:35 GMT
>>> Is it possible to efficiently split a large Vector into smaller
>>> sub-Vectors without iterating through it and adding the Objects to
[quoted text clipped - 14 lines]
> Thanks.
> Allan
sublist doesn't split the list. It only provides a view of part of the
underlying list. It does not create a new object. You can't cast it the way
you want because the object that is returned is a RandomAccessSubList, not
an ArrayList.
If you want separate ArrayLists to be created, use
lArray[j] = new ArrayList(lStates.subList(lStart, lEnd));
Which takes the List (or RandamAccessSubList) object from sublist and uses
it to create a new ArrayList.

Signature
Virgil