• Post Reply Bookmark Topic Watch Topic
  • New Topic

Copy a Portion of a List  RSS feed

 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the simplest way to create a List containing the ith element to the jth element of another List? Can it be done by a few statements without looping thru the list and copying the required elements one by one?
 
John Bartlett
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

How bout using the subList(int fromIndex, int toIndex) method available.

i.e.



Check out List in the api - List

Hope this helps,

John
[ October 27, 2006: Message edited by: John Bartlett ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!