This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Collections Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Collections" Watch "Collections" New topic
Author

Collections

Douglas Yesmunt
Greenhorn

Joined: Mar 18, 2003
Posts: 2
Can collections contain collections?
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937

Can collections contain collections?

Yes, you can have a HashMap that contains ArrayList objects as entries, and those ArrayList objects can in turn contain HashSets, and so on to infinity (well, until you run out of memory
Eugene.
Wirianto Djunaidi
Ranch Hand

Joined: Mar 20, 2001
Posts: 210

Yes. Collection can contains Collection, of course we are talking about classes that implement Collection interface.
As you will notice the methods in Collection interface like add, or contain take Object as parameter.
So you can pretty much put anything except
primitive data type in it.
Douglas Yesmunt
Greenhorn

Joined: Mar 18, 2003
Posts: 2
Thanks alot for the help
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Collections