AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Splitting Vector into smalller sub-Vectors

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help
View previous topic :: View next topic  
Author Message
Allan Bruce
Guest





PostPosted: Thu May 26, 2005 9:32 am    Post subject: Splitting Vector into smalller sub-Vectors Reply with quote



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
not, is there a collection which allows this? I dont need random access, I
am just adding blindly to a single collection, then want to split it up at
the end.

Thanks.
Allan


Back to top
Allan Bruce
Guest





PostPosted: Fri May 27, 2005 12:07 pm    Post subject: Re: Splitting Vector into smalller sub-Vectors Reply with quote





Boudewijn Dijkstra wrote:
Quote:
"Allan Bruce" <amb (AT) abc (DOT) net> schreef in bericht
news:KJ6dne1FloMoCgjfRVnytg (AT) pipex (DOT) net...

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
not, is there a collection which allows this? I dont need random access, I
am just adding blindly to a single collection, then want to split it up at
the end.


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


Back to top
Virgil Green
Guest





PostPosted: Fri May 27, 2005 10:35 pm    Post subject: Re: Splitting Vector into smalller sub-Vectors Reply with quote



Allan Bruce wrote:
Quote:
Boudewijn Dijkstra wrote:
"Allan Bruce" <amb (AT) abc (DOT) net> schreef in bericht
news:KJ6dne1FloMoCgjfRVnytg (AT) pipex (DOT) net...

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 not, is there a collection which allows this?
I dont need random access, I am just adding blindly to a single
collection, then want to split it up at the end.


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

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.

--
Virgil



Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.