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.
Rs. 20,000 US$ 300
Today: Rs. 10,000 US$150
Course Duration: 30 hrs
Posted on: March 17, 2005 If you enjoyed this post then why not add us on Google+? Add us to your Circles