-
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.
-
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.)
-
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
-
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.
-
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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks