Search code examples
javaarraysloopsparseint

How do I convert certain values of a 2 string array dimensional array to int and compare them with another integer in java?


I have a two dimensional array of strings and I want to convert the second column to integers and then compare each one with a number but I don't know how to do it inside a loop?

    int a=Integer.parseInt(array[0][1]);
    int b=Integer.parseInt(array[1][1]);
    int c=Integer.parseInt(array[2][1]);
    int d=Integer.parseInt(array[3][1]);
    int e=Integer.parseInt(array[4][1]);
    int f=Integer.parseInt(array[5][1]);
    int g=Integer.parseInt(array[6][1]);
    int h=Integer.parseInt(array[7][1]);
    int i=Integer.parseInt(array[8][1]);
    int j=Integer.parseInt(array[9][1]);


    if(number>a) return true;
    if(number>b) return true;
    if(number>c) return true;
    if(number>d) return true;
    if(number>e) return true;
    if(number>f) return true;
    if(number>g) return true;
    if(number>h) return true;
    if(number>i) return true;
    if(number>j) return true;

Solution

  • String[][] array = new String[ROWSIZE][COLUMNSIZE]
    
    for(int i = 0; i < ROWSIZE; i++){
        if(number > Integer.parseInt(array[i][1])){
          //do something
        }
    }