Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

Printing the contents of a vector (Java)

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


    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