Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Collections

 
Douglas Yesmunt
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can collections contain collections?
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 210
Ruby Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks alot for the help
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic