how to divide coloumns in a text file into seperate arrays in java

Solutions on MaxInterview for how to divide coloumns in a text file into seperate arrays in java by the best coders in the world

showing results for - "how to divide coloumns in a text file into seperate arrays in java"
Ambrine
19 Jun 2019
1Scanner scanner = new Scanner(new File(file));
2ArrayList<String> animalData = new ArrayList<String>();
3while (scanner.hasNext()) {
4    String[] columns = scanner.nextLine().split("/t");
5    String data = columns[columns.length-1];
6    animalData.add(data);
7    System.out.println(data);
8}
9
10int size = animalData.size();
11String[] arr1 = new String[size]; String[] arr2 = new String[size]; 
12String[] arr3 = new String[size]; String[] arr4 = new String[size];
13for(int i=0;i<size;i++)
14{
15    String[] temp = animalData.get(i).split("\t");
16    arr1[i] = temp[0];
17    arr2[i] = temp[1];
18    arr3[i] = temp[2];
19    arr4[i] = temp[3];
20}
21
similar questions