I want to do some efficient per-character replacements in a java String, which is the better approach, to work with .toCharArray()
or .getBytes()
?
Example code:
// big loop {
String s = "..###.##...#";
char[] c = s.toCharArray();
c[4] = '$';
c[8] = 'A';
// etc
// }
If there are some differences between these 2 approaches, or if one is advisable over the other, I would be glad to hear it.