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.

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.

String replaceAll in java

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