#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2001
    Posts
    2
    Rep 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
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2001
    Location
    On a screen near you
    Posts
    498
    Rep Power
    13
    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
  4. #3
  5. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    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");
                      }

IMN logo majestic logo threadwatch logo seochat tools logo