Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Printing the contents of a vector (Java)

  • 05-04-2012 01:32PM
    #1
    Registered Users, Registered Users 2 Posts: 1,602 ✭✭✭


    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

  • Posts: 0 ✭✭✭ [Deleted User]


    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