Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Elements types in Vectors

Status
Not open for further replies.

JontyMC

Programmer
Nov 26, 2001
1,276
GB
Hi,

I have a Vector full of integers. I want to get the integer at a certain index of the vector, but elementAt() and get() both return type Object, so I have to convert that into a string then use parseInt(). Is there not a cleaner way of doing this?

Thanks,

Jon
 
Jon - not until the next major release of Java, which will have Generics. Until then the collection classes return Objects, which you have to cast or convert into the datatype of your choice.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
If you know the size or a maximal size before, you could use a int-array.

You could use 1.5, if using a beta is ok, as mentioned before.

A vector of integers - is this a vector of somehow handled 'int''s or of 'Integer'?

You could use use a Vector of Integer.

You could wrap the Vector in a self written intVector class, which returns and accepts only 'int', and casts behind the scene.

Using the way over String sounds very ... mhh - ugly.

seeking a job as java-programmer in Berlin:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top