|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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:
edit: pay no attention to the "PHP:", it's java.. i promise. Thanks -jay Any help is appreciated. Thanks |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
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");
}
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Java Help > ints in ArrayList |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|