This can be easily done with regular expressions :
String text = "Описание серий, аннотации , изданных книг , Анонсы новых изданий, новости"; String value = text.replaceAll("\\s*,\\s*", "|"); System.out.println(value);
Conclusion:
Description of series | annotations | published books | Announcements of new editions | news
In this code, I used the method String.replaceAll(regex, replacement) , where replacement is the string with which all substrings satisfying the regex expression will be replaced.
Regular expression:
\\s*,\\s*
means - all substrings containing from zero and more spaces before the comma \\s* and the same after it.
It is also possible to replace regular expressions with objects of the java.util.regex.Pattern class and java.util.regex.Matcher objects.