Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Obtaining an int element from an arraylist?

Reply
Thread Tools

Obtaining an int element from an arraylist?

 
 
Robert Maas, see http://tinyurl.com/uh3t
Guest
Posts: n/a
 
      05-15-2005
> From: (E-Mail Removed)
> I am trying to recover an integer from an arraylist:


And an arraylist is declared to have Object not Integer as its type of
element, right? The same thing happens with an Enumeration. What I
would do is a two-step process. First downcast the Object to be an
Integer (compiler assumes it's unsafe so includes type-checking in
compiled code, which at runtime throws exception if it's not valid
cast), then in the Integer class there's a method for converting to a
primitive-type int.

Somebody else posted what looks like the right code, but didn't explain
what was really being done conceptually, so for benefit of beginners I
thought I'd explain the solution in English.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
why is int a[0] not allowed, but int* a = new int[0] is? haijin.biz@gmail.com C++ 9 04-17-2007 09:01 AM
Difference between int i, j; and int i; int j; arun C Programming 8 07-31-2006 05:11 AM
int a[10]; int* p=(int*)((&a)+1); But why p isn't equal to ((&a)+1)? aling C++ 8 10-20-2005 02:42 PM
int main(int argc, char *argv[] ) vs int main(int argc, char **argv ) Hal Styli C Programming 14 01-20-2004 10:00 PM
dirty stuff: f(int,int) cast to f(struct{int,int}) Schnoffos C Programming 2 06-27-2003 03:13 AM



Advertisments