There is a line:
String="Moscow,Astana,London";
Need to get:
String 1=Moscow; String 2=Astana; String 3=London;
Use String.split()
. I think there must be something like String.split(",");
to get the list you want.
Using streaming, the solution will be:
String str = "String=\"Moscow,Astana,London\""; String result = Arrays .stream(str.substring(str.indexOf("=\"") + 2, str.length() - 1).split(",")) .map(city -> str.substring(0, str.indexOf("=\"")) + "=" + city) .collect(Collectors.joining(";", "", ";")); System.out.println(result);
Source: https://ru.stackoverflow.com/questions/559046/
All Articles
String string = "my,some,string"; String[] strings = string.split(",");
as a result:strings[0] == "my"
,strings[1] == "some"
,strings[2] == "string"
. - DimXenon