Vector Question


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Vector Question

  1. #1
    Join Date
    May 2005
    Posts
    22

    Vector Question

    I know vectors only work with objects like Integer and String objects...

    so can i perform basic operations .. like comparing a String to a String vectior object or doing math calculations with Integer objects and normal ints? Well actualyl i know atleast the second doesnt work as ive tried it...So my question is if there is anyway to change an Integer object to a normal int data type??

    The reason im using vectors is so that i can easily remove them but i also have to do simple math aditions and string comparisons with them..so maybe vectors arnt the way to go? I dont know...help me ! Thanx.

  2. #2
    Join Date
    Dec 2003
    Location
    tx/us
    Posts
    131
    In the first case you just get the objects out and compare them using equal() or equalIgnoreCase(). For the Integer/int, that's what the API Javadocs are for.

    (Hint: *Value() methods.)

  3. #3
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    I know vectors only work with objects like Integer and String objects
    A java Vector works with all objects. If you are using a Vector for a case where
    you don't know how many objects you will be storing, its ok. If you know the number
    of objects you may as well use an object array.

    For Integer objects use the intValue() method to get the int value...
    eschew obfuscation

  4. #4
    Join Date
    May 2005
    Posts
    22
    im very dumb and new to java lol.. could i please see an example?

    like i have an int x

    and i want

    x=Vect.elementAt(y)

    where Vect is a vector of Integer Objects.

    how do u modify this to make it work with intValue() method?

    Thanks a lot.

  5. #5
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    like this:

    Integer xi=(Integer)Vect.elementAt(y);
    int x=xi.intValue();

    or:

    int x=((Integer)Vect.elementAt(i)).intValue();
    eschew obfuscation

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center