fork download
  1.  
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. class MyStringReplace {
  8.  
  9. public static void main(String a[]){
  10.  
  11. String str = "This is an example string";
  12. System.out.println("Replace char 's' with 'o':"
  13. +str.replace('s', 'o'));
  14.  
  15. System.out.println("Replace first occurance of string 'is' with 'ui':"
  16. +str.replaceFirst("is", "ui"));
  17.  
  18. System.out.println("Replacing 'is' every where with 'no':"
  19. +str.replaceAll("is", "no"));
  20. }
  21. }
Success #stdin #stdout 0.05s 4386816KB
stdin
Standard input is empty
stdout
Replace char 's' with 'o':Thio io an example otring
Replace first occurance of string 'is' with 'ui':Thui is an example string
Replacing 'is' every where with 'no':Thno no an example string