Originally posted by Vincente Aggrippino:
Thank you. I've read through the API for HashMap and that is the best solution in this case.
My original question wasn't well thought-out. I wanted to store objects of different types in an array, but I'm reading them from a text file, so they have to start out as Strings anyway.
I'm still curious, though... Is there a type of array that can contain elements that aren't all the same type? I mean, with HashMap, it looks like I can have an associative array with keys of one type and values of another type, but those values would all have to be of the same type. If it was , all of the values have to be Integers, don't they? I couldn't , could I?
Thank you,
Vince
Actually what i understand about your question is, you want to store any type of information in HashMap.
, all of the values have to be Integers, don't they? I couldn't
there is no constructer in HashMap through which you can decide what the element types in HashMap should be..
Actually if you have gone through HashMap API's then you must know that HashMap stores data in format.
So if you want to store any primitive data and you are using Jdk1.4 then you have to typecast it in it's Wrapper Class object(In jdk1.5 it's done automatically by autoboxing).. else otherwise everything in JAVA is in form of Object..
That's solve your problem..
Hope it helps you.
if still any concern then revert back ....