[Logo]
Forums Register Login
Getting Objects from Collections
I'm just wondering, in a Collection of objects, how do you get objects back out in the same type that they went in? Just like in an array where you access it by the a[10].
In the List interface, the get() method returns an Object, not the original type that went in. The Map get() does the same thing when you give it a key as a parameter.
Do you have to convert the collection to an array using toArray() to access the elements?
Thanks!
No. You have to cast the object when you get it out of the collection.
Also you may want to use instanceof to check that the type of object is what you are expecting before you cast it.
[ September 15, 2002: Message edited by: Barry Gaunt ]
Great, thanks alot guys, I got it to work like this:

Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards



All times above are in ranch (not your local) time.
The current ranch time is
Oct 20, 2017 17:43:40.