Reshma Bidikar

In this blog post, I will be explaining how you can remove a character from a String via Java. Consider the following code snippet:

package learnjava.strings;

public class RemoveCharacterDemo {

public static void main(String[] args) { 
    String str = "Hello World"; 
    String modifiedStr = str.replace("l", ""); System.out.println(modifiedStr);
    }
}

There is a method String.replace. This replaces the specified character with another character. Here, we are replacing the character ā€˜l’ with an empty character. So effectively, it is like removing the character ā€œlā€. When you run this code, you will get the following output:

Heo Word