Results 1 to 8 of 8

Thread: Java qyestion (should be easy)

  1. #1
    zombologist Senior Member doc_bean's Avatar
    Join Date
    Oct 2004
    Location
    Riding Shai-Hulud
    Posts
    5,346

    Default Java qyestion (should be easy)

    okay, I need a Vector (or another type of array) to contain only a certain Class of Objects, so that I can use the class operaters on any element of the vector without the programming environment (and possibly compiler) whining.

    I was pretty sure that this was possible using the Vector thingie from java.util.* , but i can't find the right syntax.


    HELP !


    Yes, Iraq is peaceful. Go to sleep now. - Adrian II

  2. #2
    Needs more flowers Moderator drone's Avatar
    Join Date
    Dec 2004
    Location
    Moral High Grounds
    Posts
    9,286

    Default Re: Java qyestion (should be easy)

    Not quite sure what you want, but maybe this will help:

    http://java.sun.com/j2se/1.4.2/docs/...il/Vector.html
    Syntax and access commands for the Vector class.

    Can't help you much more than this, I'm an embedded C,C++ guy. Java makes no sense to me.
    The .Org's MTW Reference Guide Wiki - now taking comments, corrections, suggestions, and submissions

    If I werent playing games Id be killing small animals at a higher rate than I am now - SFTS
    Si je n'étais pas jouer à des jeux que je serais mort de petits animaux à un taux plus élevé que je suis maintenant - Louis VI The Fat

    "Why do you hate the extremely limited Spartan version of freedom?" - Lemur

  3. #3
    zombologist Senior Member doc_bean's Avatar
    Join Date
    Oct 2004
    Location
    Riding Shai-Hulud
    Posts
    5,346

    Default Re: Java qyestion (should be easy)

    Let's say I want a collection (an array or a vector or whatever) of Strings, and I want to make sure there are no Objects of other Classes (besides String) in my collection. I'm not able to do that eventhough it should be one of the most basic operations imho.

    The more I learn about Java the less sense it makes.
    Yes, Iraq is peaceful. Go to sleep now. - Adrian II

  4. #4

    Default Re: Java qyestion (should be easy)

    Have you checked the Java tutorial on collections?

    http://java.sun.com/docs/books/tutor...ons/index.html


    Coding in eclipse (free) can help catch syntax errors (it underlines them in red as you type, just like word )

    http://www.eclipse.org/

  5. #5

    Default Re: Java qyestion (should be easy)

    Fekking logged me out, after I finished writing a long post.

    Anyways, real quick as I don't have the time to type it out again, perhaps tonight if I can get a minute.

    Try
    boolean contains(Object elem)
    Tests if the specified object is a component in this vector.
    In the api that Drone linked too. That method looks like what you are looking for.
    ..::Noobs don't own themselves!::..

  6. #6
    Needs more flowers Moderator drone's Avatar
    Join Date
    Dec 2004
    Location
    Moral High Grounds
    Posts
    9,286

    Default Re: Java qyestion (should be easy)

    Reading through the Vector page, looks like Java vectors are similiar to arrays of void pointers in C. Any class object can be added to a vector. Is this correct?

    If so, can you use the getClass() method to do what you want? Verify the class then cast appropriately to remove the compile problems?
    The .Org's MTW Reference Guide Wiki - now taking comments, corrections, suggestions, and submissions

    If I werent playing games Id be killing small animals at a higher rate than I am now - SFTS
    Si je n'étais pas jouer à des jeux que je serais mort de petits animaux à un taux plus élevé que je suis maintenant - Louis VI The Fat

    "Why do you hate the extremely limited Spartan version of freedom?" - Lemur

  7. #7
    Member Member Phatose's Avatar
    Join Date
    Dec 2003
    Location
    PA, USA
    Posts
    591

    Default Re: Java qyestion (should be easy)

    Should be able to use a generic for this.

    Vector <String> myVector;
    Last edited by Phatose; 03-08-2006 at 08:02.

  8. #8
    zombologist Senior Member doc_bean's Avatar
    Join Date
    Oct 2004
    Location
    Riding Shai-Hulud
    Posts
    5,346

    Default Re: Java qyestion (should be easy)

    Quote Originally Posted by Phatose
    Should be able to use a generic for this.

    Vector <String> myVector;
    Yes ! This was what i was looking for. Muchos Gracias !
    Yes, Iraq is peaceful. Go to sleep now. - Adrian II

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Single Sign On provided by vBSSO