differnt objects in one collection

hi all, i want to store different kinds of objects belongs to different classes in one collection, is there any available collection classes are there? plz reply me. i need it.
[190 byte] By [sampath.reddya] at [2007-11-27 1:42:38]
# 1
Any collection will do, except if you're not careful you'll run into classcastexceptions. Are you sure you need to have different classes in the same collection?
-Kayaman-a at 2007-7-12 0:59:32 > top of Java-index,Java Essentials,Java Programming...
# 2
yes, i want that, please give me any sample code for that
sampath.reddya at 2007-7-12 0:59:32 > top of Java-index,Java Essentials,Java Programming...
# 3

ArrayList alDifferentObjects = new ArrayList();

JTable table = new JTable();

JLabel label = new JLabel();

String string = new String();

alDifferentObjects.add(table);

alDifferentObjects.add(label);

alDifferentObjects.add(string);

But as the previous poster already said, it's strongly recommended putting different objects in the same collection

Nemesish3da at 2007-7-12 0:59:32 > top of Java-index,Java Essentials,Java Programming...
# 4
from j2se 5.0 onwards all collection are generic types. so it shows the errorsas followsArrayList cannot be resolved to a typetestapp/srctest.javaline 23117705016277567ArrayList cannot be resolved to a typetestapp/srctest.javaline 23117705016277568
sampath.reddya at 2007-7-12 0:59:32 > top of Java-index,Java Essentials,Java Programming...
# 5

Try this

ArrayList<Object> alDifferentObjects = new ArrayList<Object>();

JTable table = new JTable();

JLabel label = new JLabel();

String string = new String();

alDifferentObjects.add(table);

alDifferentObjects.add(label);

alDifferentObjects.add(string);

Satish_Patila at 2007-7-12 0:59:32 > top of Java-index,Java Essentials,Java Programming...
# 6
cannot be resolved to a type... I strongly assume you imported the arraylist?import java.util.ArrayList;@Satish_Patil :That is really not necessary ;) ArrayList ALWAYS contains Objects by default, so that statement is really overkill.
Nemesish3da at 2007-7-12 0:59:32 > top of Java-index,Java Essentials,Java Programming...
# 7
> That is really not necessary ;) ArrayList ALWAYS> contains Objects by default, so that statement is> really overkill.Can you give me any refrence for this ?And, I had imported "java.util.ArrayList"
Satish_Patila at 2007-7-12 0:59:32 > top of Java-index,Java Essentials,Java Programming...
# 8

The importing thing wasn't meant for you. The error he described strongly looked like he simply forgot to import it.

http://java.sun.com/javase/6/docs/api/java/util/ArrayList.html

About Object. I admit, the documentation says "E e" is the parameter. But the javadoc in Netbeans shows me it requests an Object. Also, the code I wrote works without a problem. So in this case, I simply assume he forgot to import the arraylist.

Nemesish3da at 2007-7-12 0:59:32 > top of Java-index,Java Essentials,Java Programming...