Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Printing the contents of a vector (Java)

Options
  • 05-04-2012 1:32pm
    #1
    Registered Users Posts: 1,586 ✭✭✭


    Hi all,

    Probably a very simple query for you but this has been doing my head in. I have created a stock class and it has contents like name, price , type etc. This has then been input into a vector.

    Now I want to be able to print the contents of the classes from the vector, however I keep getting what looks like memory addresses.
    Ive tried vector.get(i) and vector.elementAt(i).

    I would like to say, print the first piece of info from the instance, stock name but not the price for example.

    Can someone help me out ?

    Thanks
    Gary


Comments

  • Registered Users Posts: 5,246 ✭✭✭conor.hogan.2


    You could override toString() in your class to print out what you want your Vector to print.

    System.out.print( vector.get(i) ); Should then print it out in whatever format you define.


Advertisement