This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread 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 Head First Android this week in the Android 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: 19925
    
  43

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)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: objects and Vectors
 
It's not a secret anymore!