public static String replaceChar(String s,char sub,char with){
  int startIndex=s.indexOf(sub);
  if (startIndex == -1) {
    return s;
  }
  char[] str=s.toCharArray();
  for (int i=startIndex; i < str.length; i++) {
    if (str[i] == sub) {
      str[i]=with;
    }
  }
  return new String(str);
}

public static String replaceChar ( String s , char sub , char with ) { int startIndex = s . indexOf ( sub ) ; if ( startIndex == - 1 ) { return s ; } char [ ] str = s . toCharArray ( ) ; for ( int i = startIndex ; i < str . length ; i ++ ) { if ( str [ i ] == sub ) { str [ i ] = with ; } } return new String ( str ) ; }
replaces all occurrences of a character in a string .
