0

I have a String as below

String combinedString = "10.15%34.23%67.8% 89.00%100.00%44.44%";

As you can see above, there is a space between 67.8% and 89.00%

I would want to split them into two String arrays or two strings as below

String[] firstStringArray = {10.15%,34.23%,67.8%};
String[] secondStringArray = {89.00%, 100.00%, 44.44%};

or

String firstString = "10.15%34.23%67.8%";
String secondString = "89.00%100.00%44.44%";

Any idea on this please?

2
  • 1
    Java has a .split function that takes in a delimeter. Please see stackoverflow.com/questions/35017480/… Commented Apr 12, 2020 at 18:00
  • please share what you have tried so far Commented Apr 12, 2020 at 18:00

2 Answers 2

0

You could simply use String.split(" ") as follows:

String combinedString = "10.15%34.23%67.8% 89.00%100.00%44.44%";
String firstString = combinedString.split(" ")[0];
String secondString  = combinedString.split(" ")[1];

System.out.println(firstString);
System.out.println(secondString);

Output would look like this:

10.15%34.23%67.8%
89.00%100.00%44.44%
Sign up to request clarification or add additional context in comments.

Comments

0

You can use the white-space regex to split string based on delimiter of space, snippet as below,

    String str = "10.15%34.23%67.8% 89.00%100.00%44.44%";
    String[] splited = str.split("\\s+");

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.