Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / December 2003

Tip: Looking for answers? Try searching our database.

ArrayList help

Thread view: 
Advocated - 06 Dec 2003 23:46 GMT
Currently using:

ArrayList alist = new ArrayList();

String str = Integer.toString(location);
       alist.add(str);

       for(Iterator iter = alist.iterator(); iter.hasNext();) {
           System.out.println("list"+(String)(iter.next()));

this is working fine, but i want to assign say the first element to int a;
second element to int b, and so on
Logically it looks like:

 for(Iterator iter = alist.iterator(); iter.hasNext();) {
           System.out.println("list"+(String)(iter.next()));
a = String;

but that obviously doesnt work, any clues?
VisionSet - 07 Dec 2003 00:30 GMT
> Currently using:
>
> ArrayList alist = new ArrayList();
>
> String str = Integer.toString(location);

Integer i = new Integer(location);
alist.add(i);

>         for(Iterator iter = alist.iterator(); iter.hasNext();) {

             Integer i2 = (Integer)iter.next();
             int a = i2.intValue();

> this is working fine, but i want to assign say the first element to int a;
> second element to int b, and so on
[quoted text clipped - 3 lines]
>             System.out.println("list"+(String)(iter.next()));
> a = String;

If you really did want a String in there in the 1st place:

String s = (String)iter.next();
int a = Integer.parseInt(s);

The Docs are really quite wonderful!

--
Mike W


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.