my dog learned polymorphism
The moose likes Beginning Java and the fly likes objects and Vectors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "objects and Vectors" Watch "objects and Vectors" New topic

objects and Vectors

Donna Bachner
Ranch Hand

Joined: Oct 08, 2004
Posts: 109
How come when you put an Integer into a vector it comes out as an object. can I change this. I am trying to do math on the numbers in the vector.
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
Depends... If you're using Java 1.5 you can use the paramterized type. Even if you're not, you can put those Vectors away. Use an ArrayList instead.

Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Donna Bachner
Ranch Hand

Joined: Oct 08, 2004
Posts: 109
Thanks,I'll try that and let you know how it works.
Henry Wong

Joined: Sep 28, 2004
Posts: 20538

Even if you are not using Java 5, you can always cast it back to an Integer. It may be an Object reference, but it should be the object that you stored, which means it should be an Integer.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
I agree. Here's the link:
subject: objects and Vectors
It's not a secret anymore!