This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "objects and Vectors" Watch "objects and Vectors" New topic
Author

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
author
Sheriff

Joined: Sep 28, 2004
Posts: 18756
    
  40

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.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: objects and Vectors