# string to integer conversion

• 10-17-2011, 03:18 PM
boys21
string to integer conversion
hi,

i am working with excel and java. by default, value extracted from a cell of excel sheet is string. In a column i have 3000 numerical values. As excel sheet cell is returning string, i created a string array to store column elements. when i try to convert those string values to integer,

1.It is throwing an exception of array index out of bounds? why?

2. also, when i tried to print the string values directly, it is throwing exception in middle of values, but still i could see all values? but, with exception message.

br,
boys21
• 10-17-2011, 04:00 PM
KevinWorkman
Re: string to integer conversion
If you want help, you'll have to provide an SSCCE that demonstrates the problem. Otherwise, we have no idea what you're doing.
• 10-17-2011, 04:19 PM
boys21
Re: string to integer conversion
ok..
assume my excel sheet have 1000 rows, 5 columns
iam extracing data from excel sheet cells and trying to make statistical analysis and modifications on excel data through arrays,

//create a work book to access data.

//created a multi dimensional array of string datatype to save the data into cells

string [][] x;
x=new string [column][row];

TO copy contents from a cells to array; i used nested for loops

for loop(column){

for loop (row)
{
x[i][j]=cell.getcontents(column,row);
}
}

NOw, i hold all cells data of excel sheet in a multi dimensional array.

assume i want to manuplate, 2nd column elements to make some analysis.

excel Cell return string type , so i used string array to store. but actually they are numerical values in the cells, so i have to type cast them to make anaylsis. as i only need 2nd column elements to manipulate, i took a single dimensional array and made typecasting. HERE IT is throwing EXCEPTION.

int[] analysis;
analysis =new integer[row];

for(int c=0;c<row;c++){

analysis[c]=Integer.parseInt(x[1][c]);//second column elements //Here i get exception.
}
• 10-17-2011, 04:58 PM
JosAH
Re: string to integer conversion
You're mixing up row and colum index values; normally a row runs 'horizontally' and the colums run from left to right; the row index is the first index in a two dimensional array (and the column index is the second index). Draw it on paper while you fix your code; rows are on top of eachother. columns are next to eachother.

kind regards,

Jos