There is a line:

String="Moscow,Astana,London"; 

Need to get:

 String 1=Moscow; String 2=Astana; String 3=London; 
  • String string = "my,some,string"; String[] strings = string.split(","); as a result: strings[0] == "my" , strings[1] == "some" , strings[2] == "string" . - DimXenon
  • if you have been given the correct answer, check it out for those who will later come across this topic. - Denis

2 answers 2

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);