• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt on Collection

 
Ramesh Shanmugam
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can any one tell where collections are used in Real world Projects. An Example
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They are used absolutely all the time. Anywhere you need a data structure which holds collections of objects.
 
Ramesh Shanmugam
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please give me a small example
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ehm, OK. The application I am currently working on hold user authorisation data (i.e. the various roles a user may belong to) in a Map. That do?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you've done some database modeling or UML you've seen one-to-many relationships, like parent has many children. When we do these in Java the "one" often has a collection of the "many" things.

Any time you find yourself saying "for each" or "for every" like "for each child, pay weekly allowance" you're probably going to find a collection.

Any of that help?
 
Vj Kamath
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Collections are used to store objects.
Some real world examples:

HashMap could be used to store key value pairs to load a dropdown box.
ArrayList could be used to store the data returned into a resultset from a database.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ramesh Shanmugam:
Can any one tell where collections are used in Real world Projects. An Example

Are you asking for specific code examples or high-level conceptual examples? If the later, all you have to do is turn on your computer to see Collections (or in computer science parlance, data structures) in action. Okay, you probably don't actually see them, but the operating system uses them under the hode constantly. For example, the printer has a queue to keep track of the next job to print. A program uses a stack to keep track of the address of the instruction when a function is called so that it can return there when the function returns.

These are quite low-level system examples, but as the other examples given above, there are also higher-level examples as well.

Cheers and Keep Coding (TM)

Layne
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic