First thing we don't know how many lines are there in the csv file. So it's impossible to determine the length of the 2d array. We have to increment the size of the array according to this case. But, normally it's impossible to re-size the array with java. So we create new array and copy contents of source array when we need to re-size the array.
Solution for you:
int i = 0;//line count of csv
String[][] data = new String[0][];//csv data line count=0 initially
while ((thisLine = myInput.readLine()) != null) {
++i;//increment the line count when new line found
String[][] newdata = new String[i][2];//create new array for data
String strar[] = thisLine.split(";");//get contents of line as an array
newdata[i - 1] = strar;//add new line to the array
System.arraycopy(data, 0, newdata, 0, i - 1);//copy previously read values to new array
data = newdata;//set new array as csv data
}
Create test to view csv data:
for (String[] strings : data) {
for (String string : strings) {
System.out.print("\t" + string);
}
System.out.println();
}
Output:
Id name
E1 Tim
A1 Tom