java - Read file and store values into two arrays, one for each line -
i got code here:
try{ filereader file = new filereader("/users/tda/desktop/readfiles/tentares.txt"); bufferedreader br = new bufferedreader(file); string line = null; while((line = br.readline()) != null){ string[] values = line.split(","); grp1 = new int[values.length]; for(int i=0; i<grp1.length; i++){ try { grp1[i]= integer.parseint(values[i]); }catch (numberformatexception e) { continue; } } system.out.println(arrays.tostring(grp1)); } system.out.println(""); br.close(); }catch(ioexception e){ system.out.println(e); }
this file im reading contains.
grp1:80,82,91,100,76,65,85,88,97,55,69,88,75,97,81 grp2:72,89,86,85,99,47,79,88,100,76,83,94,84,82,93
right im storing values 1 int array. if wanted store each line of values 2 arrays?
thought using arrays.copyofrange somehow, , copy values int array 2 new arrays.
before while
list<int[]> groups = new arraylist<>();
before end of loop:
groups.add(grp1);
afterwards:
for (int[] grp : groups) { ... }
a list
useful growing "array".
groups.size() grp1.length groups.get(3) grp1[3] groups.set(3, x) grp1[3 = x
Comments
Post a Comment