I have a file named "data.txt" and it look like this:
B,C,1,360,370,380,390,400,410,420
B,C,2,365,375,385,395,405,415,425
B,G,3,360,370,380,390,400,410,420
C,D,1,370,380,390,400,410,420,430
C,D,4,385,395,405,415,425,435,445
C,G,5,360,370,380,390,400,410,420
D,G,3,365,375,385,395,405,415,425
G,B,3,385,395,405,415,425,435,445
G,D,3,380,390,400,410,420,430,440
I have to do a function like this Function(String s1, String s2, int x)
it will
output the value after the second comma from the left if it satisfies the condition:
-s1 must equal the first value
-s2 is equal to the value after the first comma
-Finally return the first value bigger than "x" from the 3rd comma. Example Function ("B", "C", 364) = 1 and Function ("B", "C", 366) = 2.
I tried to read the file line by line then split using this
BufferedReader reader;
String fileName = "data.txt";
try(Stream<String> stream = Files.lines(Paths.get(fileName),StandardCharsets.UTF_8)){
stream.forEach(line ->{
System.out.println(line);
});
} catch (Exception e) {
e.printStackTrace();
}
So i can print the file in Console. I add split (). To take each character and compare it, but the results printed in the Console are not as I thought.
BufferedReader reader;
String fileName = "data.txt";
try(Stream<String> stream = Files.lines(Paths.get(fileName),StandardCharsets.UTF_8)){
stream.forEach(line ->{
String[] newline=line.split(",");
System.out.println(newline);
});
} catch (Exception e) {
e.printStackTrace();
}
Here is the console:
[Ljava.lang.String;@8646db9
[Ljava.lang.String;@37374a5e
[Ljava.lang.String;@4671e53b
[Ljava.lang.String;@2db7a79b
[Ljava.lang.String;@6950e31
[Ljava.lang.String;@b7dd107
[Ljava.lang.String;@42eca56e
[Ljava.lang.String;@52f759d7
[Ljava.lang.String;@7cbd213e
I'm stuck at here now.