How do I insert a character at a specific index in a string builder variable? Fo
ID: 3930805 • Letter: H
Question
How do I insert a character at a specific index in a string builder variable?For example:
StringBuilder temp = new StringBuilder(how to);
I want to insert char 'j' at temp[3];
Temp would now = howj to. Thanks. How do I insert a character at a specific index in a string builder variable?
For example:
StringBuilder temp = new StringBuilder(how to);
I want to insert char 'j' at temp[3];
Temp would now = howj to. Thanks.
For example:
StringBuilder temp = new StringBuilder(how to);
I want to insert char 'j' at temp[3];
Temp would now = howj to. Thanks.
Explanation / Answer
public class StringBuilderDemo {
public static void main(String[] args) {
StringBuilder temp = new StringBuilder("how to");
// insert character value at position 3
temp.insert(3, 'j');
System.out.println(temp.toString());
}
}
/* sample output
howj to
*/
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.