Hello Guys I have a txt file below, I need to store the second column data but it gives me an error since some lines have 1 some have 2 and some have 3 input in each line. How can I solve that problem?
5
3 4
3 4
3 3
3 4
3 3
3 4
3 3
3 2
3 4
3 3
3 2
3 1
3 4
3 3
3 2
3 1
3 0
1
2
5 3 4
3 4
3 4
3 3
3 4
3 3
3 4
3 3
3 2
3 4
3 3
3 2
3 1
3 4
3 3
3 2
3 1
3 0
1
2
5 4 6
4 4
4 4
4 4
4 4
4 4
4 4
4 3
4 3
4 3
4 3
4 4
4 4
1
2
5 4 6
0
Here is what I did, I tried to differentiate as the size and in the other way but still cant get the answer...
String line = "";
ArrayList<String> numbers= new ArrayList<String>();
try {
String sCurrentLine;
br = new BufferedReader(new FileReader("input1.txt"));
int n = 0;
while ((sCurrentLine = br.readLine()) != null) {
String[] arr = sCurrentLine.split(" ");
int size = arr.length;
List<String> list = ConvertToList.convertArrayToList(arr);
List<Integer> listOfInteger = convert.convertStringListToIntList(list, Integer::parseInt);
if (list.size() == 2) {
line.split("\\s+");
numbers.add(line.split("\\s+")[0]);
System.out.println(numbers);
}
}
} catch(Exception e) {
e.printStackTrace();
}