This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Vector <Object>

 
pong lai pong
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 349
Eclipse IDE Hibernate Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi pong,

What do you expect to be printed?
 
Raymond Tong
Ranch Hand
Posts: 240
2
IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20381
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
pong lai pong
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so how can i print/access the student name, number??
 
Raymond Tong
Ranch Hand
Posts: 240
2
IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic