How can I swap two characters in a String? For example, \"abcde\" will become \"bacde\".
String
\"abcde\"
\"bacde\"
StringBuilder sb = new StringBuilder("abcde"); sb.setCharAt(0, 'b'); sb.setCharAt(1, 'a'); String newString = sb.toString();