Home Java String-examples String replaceAll in java
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

String replaceAll in java

Advertisement
In this section you will learn about replaceAll() method in java, This will replace each of the sub string with the given replacement. This method will return the resulting string.

String replaceAll in java

In this section you will learn about replaceAll() method  in java, This will replace each of the sub string  with the given replacement. This method will return the resulting string.

Syntax :

public string replaceAll(String regx, String replacement)

Here regx is regular expression to which string is to be matched and replacement is the string which would replace the original string.

public class ReplaceAll 
{
 public static void main(String args[])
 {
	 String st="Welcome rose India";
	 System.out.print("Original String is = ");
	 System.out.println(st);
	 System.out.print("After Replacing all  the string = ");
	  String str=st.replaceAll("Welcome"," All blessings with"); 
      System.out.println(str);
 }
	
}

Output :  After compiling and executing the above program

Original String is = Welcome rose India
After Replacing all the string = All blessings with rose India

Advertisement

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: May 20, 2013

Ask Questions?    Discuss: String replaceAll in java  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com