Replace a Specified Character In a String Using Java

Last Updated on December 27, 2020 by Roshan Parihar

In this tutorial, learn how to replace a specified character from a string using java. The short answer is: use java replace() to replace or remove the specified letter from the string.

You can remove the specified character or add a new character as a replacement. The replacement of the character from the string gives a new string with the added letter. You can also add space in place of the specified character from a string.

How to Replace a Specified Character From String Using Java

To replace the character from the specified character in a string using java. You can place a new character in place of the mentioned string using replace()

The replace function of java takes two arguments. The first argument is the character from the string you want to replace. The second argument is the new character you want to replace with.

Output

This is my new string.

The above example contains the replaced string. You can use any character in place of the old mentioned character from a string. Replace words, symbols, or any other character as per your requirement. You may also like to read how to remove the first letter of the string using java.

You may also like to read

I hope you like this tutorial on how to replace a specified character from a string using java.

References