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.
}
You can also use the
StringBuilderclass which is mutable.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:
This avoids creation of unnecessary string objects.