- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to replace one specific character with another
Use the replace() method to replace a specific character with another. Let’s say the following is our string and here we are replacing a whitespace with a $ character.
String str1 = "Orange is the new Black!";
Now, use the replace() method to replace a character with $
str1.replace(' ', '$');
Example
public class Demo { public static void main(String[] args) { String str1 = "Orange is the new Black!"; System.out.println("String: "+str1); String str2 = str1.replace(' ', '$'); System.out.println("Updated string: "+str2); } }
Output
String: Orange is the new Black! Updated string: Orange$is$the$new$Black!
- Related Articles
- Java Program to Replace the Spaces of a String with a Specific Character
- Java Program to Replace a Character at a Specific Index
- Golang program to replace the spaces of string with a specific character
- Replace one string with another string with Java Regular Expressions
- Python Program to Replace the Spaces of a String with a Specific Character
- Java Program to replace all occurrences of a given character with new character
- Golang program to replace a character at a specific index
- C++ Program to Replace a Character at a Specific Index
- C# Program to Replace Items in One Hashtable with Another Hashtable
- Replace String with another in java.
- Java Program to replace all occurrences of given String with new one
- How to replace an HTML element with another one using JavaScript?
- Java Program to replace only first occurrences of given String with new one
- C# Program to replace a character with asterisks in a sentence
- Replace all words with another string with Java Regular Expressions

Advertisements