• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Containers

 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I recenlty read about "containers" in Java. Or objects that store other objects. Can anyone give me an example of when I would need to use an object in a container?
Thanks,
Landon
 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am not sure in what context u read these container, If you are aware of
Vectors, here a Vector can act as a container and can store objects of any type.
In general example suppose you want to store an Object of type String and one array object of integer, In a vector you can add both and then again u can takeout to use this.
you can refer to any java book for details.
thanks
Anurag
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are several different kinds of containers (usually called "Collections" in Java.) Of course they all have in common that they maintain a group of objects, so one useful scenario is just that: a video game program might need a list of Monsters. You could use an array, but a collection like ArrayList or LinkedList makes it easy to add and delete items from the collection (as Monsters are killed or hatched) without worrying about the changing the size of the array.
Other collections have more specialized uses. A Set lets you hold a collection of items but automatically removes duplicates. By iterating over the words in a document and adding each one (as a String) to a Set, you get a collection of the unique words in the document. If it's a SortedSet, then you automatically get that collection in sorted order.
A Map is a very useful collection that lets you look up things quickly given a key. If an application included a few thousand Person objects (a personnel application, perhaps) then you might store those Person objects in a Map using their name as the key; then you can very quickly look up a Person by name.
Collections have a million and one uses, in Java and in any language.
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
A container is a component which can contain other components inside itself. It is also an instance of a subclass of java.awt.Container. java.awt.Container extends java.awt.Component so containers are themselves components.
In general components are contained in a container. An applet is one container. Other containers include windows, frames, dialogs, and panels. Containers may contain other Containers.
Every container has a LayoutManager that determines how different components are positioned within the container.
In short containers contain components. Components are positioned inside the Container according to a LayoutManager. Since containers are themselves components, containers may by placed inside other containers. This is really a lot simpler than it sounds. Applets provide a ready-made container and a default LayoutManager, a FlowLayout.
bhramaresh
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah, great things going on here! Be aware we are talking about two very different kinds of containers. It's bad to overload English words!
Smalltalk people called their Collection things "containers" and the term still hangs on. If you start with the Collection interface and look at some of the implementations you'll find lots of good ways to stash a bunch of objects away until you need them later. I vote we try to call these Collections and not containers.
Java AWT and Swing folks have their own concept of containers, and those are UI widgets that can contain other UI widgets. Frames can contain panels, panels can contain buttons, panels can contain panels, on and on forever. That's where we use layout managers to influence (I can't quite say control) visual layouts.
Now, can we get Landon back online to clarify which kind he was asking about?
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic