Java String replace

Introduction

The replace() method has two forms.

String replace(char original, char replacement) 
String replace(CharSequence original, CharSequence replacement) 

public class Main {

  public static void main(String[] args) {
    String s = "Hello".replace('l', 'w');
    System.out.println(s);/*from   ww  w  .ja  v  a2 s .c om*/
    
    s = "Hello World".replace("World", "demo2s.com");
    System.out.println(s);
  }
}



PreviousNext

Related