• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Collection framework query

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Solution 1: We can copy the 5 elements from listA to listB and return listB. But i dont want to go with this as it will unnecessarily needs me to create listB.
I want something from Collection framework which can help me here.

THanks,
Maverick

 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out the API docs for a method which will let you generate a sublist (hint)
Also please check your private messages for an important administrative matter
 
Maverick Schueler
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Maneesh..

I was able to find the sublist function.


It returns List reference instead of ArrayList.
 
Ranch Hand
Posts: 514
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello!

Note that any method you call on SubList is delegated to ArrayList you obtained SubList from.
This means that any modifications you make to SubList also modify ArrayList.
But any modifications done to ArraList after sublist was returned to you will result in
ConcurrentModificationException when you call any method (even size()) of SubList.
Be aware that after sublist was returned to you do not call methods of ArrayList in order to use sublist safely.

The best is to explore thoroughly java collections framework on my Internal life of java collections series
 
reply
    Bookmark Topic Watch Topic
  • New Topic