Replace a Specified Character In a String Using Java

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 many 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 first letter of the string using java.

You may also like to read

Hope, you like this tutorial of how to replace a specified character from a string using java. If you have any query regarding the tutorial, please comment below.

References

Also tell me, which method you are using to replace a character from a string using java.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.