Ich habe diese Zeichenfolge, die ich aus einer Textdatei nehme.verwirrt wie .split() in Java funktioniert
"1 normal 1 [(o, 21) (o, 17) (t, 3)]"
Ich möchte 1, normal, 1, o, 21, 17, t, 3
in einem String-Array nehmen.
Scanner inFile = new Scanner(new File("input.txt");
String input = inFile.nextLine();
String[] tokens = input.split(" |\\(|\\)|\\[\\(|\\, |\\]| \\(");
for(int i =0 ; i<tokens.length; ++i)
{
System.out.println(tokens[i]);
}
Ausgang:
1
normal
1
o
21
o
17
t
3
Warum gibt es Räume in dem Array gespeichert werden.