array of objects

Discussion in 'Java' started by Psybar Phreak, Sep 30, 2003.

  1. hi all,

    i have an array of objects, and i can get each object out, but what i want,
    is to get the value of a variable from that object that ive pulled out of
    the array.

    how?

    thanks

    PP
    Psybar Phreak, Sep 30, 2003
    #1
    1. Advertising

  2. dont worry.

    i got it =)

    PP


    "Psybar Phreak" <> wrote in message
    news:3f79786d$0$26924$...
    > hi all,
    >
    > i have an array of objects, and i can get each object out, but what i

    want,
    > is to get the value of a variable from that object that ive pulled out of
    > the array.
    >
    > how?
    >
    > thanks
    >
    > PP
    >
    >
    Psybar Phreak, Sep 30, 2003
    #2
    1. Advertising

  3. Psybar Phreak

    fozzy Guest

    Psybar Phreak wrote:

    > hi all,
    >
    > i have an array of objects, and i can get each object out, but what i want,
    > is to get the value of a variable from that object that ive pulled out of
    > the array.


    Cast the object to the object supposed to be pulled out. Now you can
    retreive the value:

    myVar = ((myClass)objectArray).getTheVar();


    --
    len
    fozzy, Sep 30, 2003
    #3
  4. [Other newsgroups removed. Please don't crosspost unless you really
    have to.]

    Psybar Phreak:

    >i have an array of objects, and i can get each object out, but what i want,
    >is to get the value of a variable from that object that ive pulled out of
    >the array.


    You can call toString() on any object and hope that the class delivers
    a String value that is sufficient for you.

    Or you know what class these objects are in and do an explicit cast.
    As an example, if you know that you have a String do that:

    String s = (String)array;

    (if you want to convert the i'th element of array to String).

    Regards,
    Marco
    --
    Please reply in the newsgroup, not by email!
    Java programming tips: http://jiu.sourceforge.net/javatips.html
    Other Java pages: http://www.geocities.com/marcoschmidt.geo/java.html
    Marco Schmidt, Sep 30, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    369
    Victor Bazarov
    Mar 29, 2005
  2. John Machin
    Replies:
    2
    Views:
    274
    Reinhold Birkenfeld
    Sep 3, 2005
  3. 7stud
    Replies:
    11
    Views:
    661
    Dennis Lee Bieber
    Mar 20, 2007
  4. markspace
    Replies:
    1
    Views:
    368
    markspace
    Jun 25, 2009
  5. Roedy Green
    Replies:
    1
    Views:
    417
    Roedy Green
    Jun 25, 2009
Loading...

Share This Page