I need to replace a character at a certain position in String ().
Example - Change character [21] to 'X':
Original String = 01078989469150999134B B 2116456
Modified String = 01078989469150999134B X 2116456
I'm using the following code:
StringBuffer sb = new StringBuffer('01078989469150999134BB2116456');
sb.setCharAt(21, 'X');
String novaStr = sb.toString();
But for what I read and understood, getting to use StringBuffer () is expensive, especially in this process which will be used several times (barcode reading).
The question is - Is this method effective? Is there a better and more efficient way?