Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Iron Speed
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old March 19th, 2002, 06:44 PM
phast phast is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2001
Posts: 2 phast User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
ints in ArrayList

Hi,
I am retreiving some numbers from an HTML form, converting them to int and then storing them in an ArrayList.

I'm having trouble parsing the ArrayList to check if the numbers are less than 70. I can't cast the ArrayList datatype to an int for the purpose of comparing. I get a ClassCastException with this method, and any other things I try result in a "incompatible data type" complier error.

PHP Code:
for (int i 0scoreList.size(); i++) { 
                  
out.println(scoreList.get(i));
                  
String score scoreList.get(i); 
                  
int i_score Integer.parseInt(score);
                  if (
i_score 70) {
                        
out.println((String)scoreList.get(i));
                        
out.println("insert some CA's");
                  } 


edit: pay no attention to the "PHP:", it's java.. i promise.

Thanks
-jay

Any help is appreciated. Thanks

Reply With Quote
  #2  
Old March 19th, 2002, 08:32 PM
Marky_Mark Marky_Mark is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2001
Location: On a screen near you
Posts: 498 Marky_Mark User rank is Private First Class (20 - 50 Reputation Level)Marky_Mark User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Make sure you have the correct import for this
and i would use length over size when working with arrays


Code:


for (int i = 0; i < scoreList.length; i++) { 
                  
       int ij = Integer.valueOf(scoreList[i]).intValue();

         if(ij < max){          
        System.out.println(ij);
        }
                  
                  
   }




Mark
__________________
100 trillion calculations per nanosecond

Reply With Quote
  #3  
Old April 1st, 2002, 09:57 AM
Nemi Nemi is offline
Clueless llama
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Feb 2001
Location: Lincoln, NE. USA
Posts: 2,353 Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Days 12 h 35 m 19 sec
Reputation Power: 111
I believe the reason you are getting a classCastException is because you are trying to put an Object type into a String:

Code:
for (int i = 0; i < scoreList.size(); i++) { 
                  out.println(scoreList.get(i));
                  String score = scoreList.get(i); //this returns a type Object
                  int i_score = Integer.parseInt(score);
                  if (i_score < 70) {
                        out.println((String)scoreList.get(i));
                        out.println("insert some CA's");
                  }

--------------------------
Should be :

for (int i = 0; i < scoreList.size(); i++) { 
                  out.println(scoreList.get(i));
                  String score = (String)scoreList.get(i); 
                  int i_score = Integer.parseInt(score);
                  if (i_score < 70) {
                        out.println((String)scoreList.get(i));
                        out.println("insert some CA's");
                  }

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > ints in ArrayList


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway