This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Vector <Object> Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Vector <Object>" Watch "Vector <Object>" New topic
Author

Vector <Object>

pong lai pong
Greenhorn

Joined: Aug 02, 2011
Posts: 3
hi,
im trying to put an object into a vector but when i try to print the elements of the vector, it shows different characters.....
this is a sample of what ive done


what did i do wrong? the name doesnt show up. does it mean that the vector has different elements in it?
please help me im a total noob
Ananth Chellathurai
Ranch Hand

Joined: Nov 21, 2007
Posts: 349

Hi pong,

What do you expect to be printed?


Ananth Chellathurai [Walk on software]
Raymond Tong
Ranch Hand

Joined: Aug 15, 2010
Posts: 230
    
    2

pong lai pong wrote:
it prints : "Elements of vector:[Student@19821f]"
what did i do wrong? the name doesnt show up. does it mean that the vector has different elements in it?
please help me im a total noob

sVector is a Vector
You are printing Vector but not Student Name.
pong lai pong
Greenhorn

Joined: Aug 02, 2011
Posts: 3
I wanted to seee the name David and he student number which is 1....because im gonna manipulate it later...
but i dont know how to access it
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

You'll need to override the toString() method in class Student to print out something useful. Otherwise it will inherit the implementation from the super class, which in this case is Object. This implementation returns the class name, followed by an @ and the hexadecimal representation of the hash code.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
pong lai pong
Greenhorn

Joined: Aug 02, 2011
Posts: 3
so how can i print/access the student name, number??
Raymond Tong
Ranch Hand

Joined: Aug 15, 2010
Posts: 230
    
    2

pong lai pong wrote:so how can i print/access the student name, number??

The following tutorial gives your an example
http://download.oracle.com/javase/tutorial/java/javaOO/usingobject.html
I recommend you to start reading from Chapter 1 to understand more about Java
 
Consider Paul's rocket mass heater.
 
subject: Vector <Object>
 
Similar Threads
printing out all my instances...toString() method..
Puzzle for JavaProgrammers
Arrays: Calling input from other methods and classes
String to Object array
Gradebook