Latest Tutorials| Questions and Answers|Ask Questions?|Site Map

Home Tutorials Java StringExamples java.lang.string.replace()

Related Tutorials


Share on Google+Share on Google+


the replace() method of Java String Class.

The example discuss about the replace() method of Java String Class in Java.

Use of string.replace() method in Java
For a example if you wants to replace certain characters from the given string with your ones...then you should use the replace() method. Basically, replace method in Java replace the given char from the new one.

public String replace(char oldChar, char newChar)

See the example below...

public class Replacing
public static void main(String[] args)
String str = "Is Java Programming.";

//will replace all the 's' characters with 'n' character.
String toStr = str.replace('s', 'n');

// Display the strings for comparison.
System.out.println("Orignal String = " + str);
System.out.println("New String = " + toStr);

the Output is:
Orignal String = Is Java Programming.
New String = In Java Programming.


If you enjoyed this post then why not add us on Google+? Add us to your Circles

Liked it!  Share this Tutorial

Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: March 17, 2005

Related Tutorials

Discuss: java.lang.string.replace()  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image