The setCharAt() method in java StringBuilder class is used to set the character at the specified index of a string builder object. This method accepts two parameters, the index at which the character needs to be set and the character itself.
Example 1: StringBuilder str = new StringBuilder("Hello World"); str.setCharAt(6, '-'); System.out.println(str.toString()); // Output: "Hello-World"
This example replaces the character at index 6 with a dash (-) in the given string "Hello World".
Example 2: StringBuilder str = new StringBuilder("Java is a popular programming language"); str.setCharAt(0, 'j'); System.out.println(str.toString()); // Output: "java is a popular programming language"
This example changes the first character of the string to lowercase.
The setCharAt() method is part of the java.lang package library.
Java StringBuilder.setCharAt - 30 examples found. These are the top rated real world Java examples of StringBuilder.setCharAt extracted from open source projects. You can rate examples to help us improve the quality of examples.