Delete char at position in string

java, string

Solution

Use a StringBuilder, which has the method `deleteCharAt()`. Then, you can just use `stringBuilder.toString()` to get your string.

EDIT, here's an example:

public static void main(String[] args) {
    String string = "bla*h";
    StringBuilder sb = new StringBuilder(string);
    sb.deleteCharAt(3);
    // Prints out "blah"
    System.out.println(sb.toString());
}

Problem

Currently, I am working on a project that requires to delete a char at a set position in a string. Is there a simple way to do this?

Original source