Java String.replaceAll(String regex, String replacement)

Syntax

String.replaceAll(String regex, String replacement) has the following syntax.

public String replaceAll(String regex,   String replacement)

Example

In the following code shows how to use String.replaceAll(String regex, String replacement) method.


public class Main {
//from w ww  .  j a v a2  s .com
  public static void main(String args[]) {

    String str = "This is a test from java2s.com.";

    System.out.println(str.replaceAll("is", "are"));
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable