How to remove single character from a String by index

java, string

Solution

You can also use the `StringBuilder` class which is mutable.

StringBuilder sb = new StringBuilder(inputString);

It has the method `deleteCharAt()`, along with many other mutator methods.

Just delete the characters that you need to delete and then get the result as follows:

String resultString = sb.toString();

This avoids creation of unnecessary string objects.

Problem

For accessing individual characters of a String in Java, we have `String.charAt(2)`. Is there any inbuilt function to remove an individual character of a String in java? Something like this: ``` if(String.charAt(1) == String.charAt(2){ //I want to remove the individual character at index 2. } ```

Original source