The error is because indexOf
is expecting a String
not a char
so all you have to do is wrap it with String.valueOf
sb.setCharAt(sb.indexOf(String.valueOf((sb.charAt(4)))), sb.charAt(0));
outputs
just going nuts
justjgoing nuts
Modern IDEs should catch this compile time error while you type even offer the solution (in the case below IntelliJ):