public static String replace(String str,char oldChar,String newStr){
  StringBuffer buf=new StringBuffer();
  for (int i=0; i < str.length(); i++) {
    char ch=str.charAt(i);
    if (ch == oldChar) {
      buf.append(newStr);
    }
 else {
      buf.append(ch);
    }
  }
  return buf.toString();
}

public static String replace ( String str , char oldChar , String newStr ) { StringBuffer buf = new StringBuffer ( ) ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { char ch = str . charAt ( i ) ; if ( ch == oldChar ) { buf . append ( newStr ) ; } else { buf . append ( ch ) ; } } return buf . toString ( ) ; }
returns a string with all occurrences of oldchar replaced by newstr
