File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


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: 18876
    
  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)
 
GeeCON Prague 2014
 
subject: objects and Vectors