replace first character in string java code example
Example 1: replace character in string java
String str = "..............................";
int index = 5;
char ch = '|';
StringBuilder string = new StringBuilder(str);
string.setCharAt(index, ch);
System.out.println(string);
Example 2: replace everything before a character in java
result = result.split("\n")[0];
Example 3: java replaceall single character
.replaceAll("(?<!\\S)[^ ](?!\\S)", " ").trim()