- 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
How to use Java string replace method?
The replace() method of the String class returns a new string resulting from replacing all occurrences of oldChar in this string with newChar.
Example
import java.io.*; public class Test { public static void main(String args[]) { String Str = new String("Welcome to Tutorialspoint.com"); System.out.print("Return Value :" ); System.out.println(Str.replace('o', 'T')); System.out.print("Return Value :" ); System.out.println(Str.replace('l', 'D')); } }
Output
Return Value :WelcTme tT TutTrialspTint.cTm Return Value :WeDcome to TutoriaDspoint.com
- Related Articles
- Java String replace() method example.
- Replace Character in a String in Java without using replace() method
- How to replace Digits into String using Java?
- How to replace characters on String in Java?
- How to use Java String.split() method to split a string by dot?
- How to use Java substring Method?
- How to use JavaScript to replace a portion of string with another value?
- Java String replace(), replaceFirst() & replaceAll() Methods
- Replace String with another in java.
- How to use replace () in Android textview?
- How to replace string using JavaScript RegExp?
- How can I use MySQL replace() to replace strings in multiple records?
- Replace one string with another string with Java Regular Expressions
- How to use subSet() method of Java NavigableSet Class
- How to use headSet() method of Java NavigableSet Class

Advertisements