I need a way to separate a string like the following:
"0.1253729 09863637 02937382 029828020"
I want to remove each of the information and store it in an array .
obs: I'm reading from .txt file .
I need a way to separate a string like the following:
"0.1253729 09863637 02937382 029828020"
I want to remove each of the information and store it in an array .
obs: I'm reading from .txt file .
Use the Java split function.
As a parameter of the split function, you pass the separator that in the case is the space.
String foo = "Palavra1 Palavra2 Palavra3";
String[] split = foo.split(" ");
split[0] = "Palavra1";
split[1] = "Palavra2";
split[2] = "Palavra3";
That way, here too it works, using regex and Stream
:
String str = "0.1253729 09863637 02937382 029828020";
String[] array = Pattern.compile("\s+")//regex que filtra um ou mais espaços
.splitAsStream(str)//quebra a string em um array de Stream
.toArray(String[]::new);//converte num array de String
See working on ideone .
So I understand you want to break the string in the "", which would be the range.
You can use the split function:
String[] strRetorno = "0.1253729 09863637 02937382 029828020".split(" ");