fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. class Ideone
  8. {
  9. public static void replaceAll(StringBuffer builder, String from, String to)
  10. {
  11. int index = builder.indexOf(from);
  12. while (index != -1)
  13. {
  14. builder.replace(index, index + from.length(), to);
  15. index += to.length();
  16. index = builder.indexOf(from, index);
  17. }
  18. }
  19.  
  20. public static void main (String[] args) throws java.lang.Exception
  21. {
  22. StringBuffer sb = new StringBuffer("Foo Bar Baz Poo");
  23. replaceAll(sb, "Bar", "Laa");
  24. System.out.println(sb);
  25. }
  26. }
Success #stdin #stdout 0.09s 320320KB
stdin
Standard input is empty
stdout
Foo Laa Baz Poo