String s = "new String";
String replaced = s.replace("new","Test");
^ ^
old new char
String str = in.nextLine(); //Original String
char cr = in.next().charAt(0); // character to replace
int index = in.nextInt(); // Index where replaced
str = str.substring(0, index) + cr + str.substring(index + 1);// modified string
// Algorithm to replace a specific character from end of string.
// From: 10.000.000.00
// To: 10.000.000,00
String cash = "10.000.000.00";
StringBuilder temp1 = new StringBuilder(cash);
StringBuilder temp2 = new StringBuilder(temp1.reverse().toString().replaceFirst("[.]", ","));
System.out.println(temp2.reverse());
String str = "..............................";
int index = 5;
char ch = '|';
StringBuilder string = new StringBuilder(str);
string.setCharAt(index, ch);
System.out.println(string);
// We want to replace every # with a 8
String larry = "Larry is # years old";
String newString = larry.replace("#", "8");
public class JavaExample{
public static void main(String args[]){
String str = new String("Site is BeginnersBook.com");
System.out.print("String after replacing com with net :" );
System.out.println(str.replaceFirst("com", "net"));
System.out.print("String after replacing Site name:" );
System.out.println(str.replaceFirst("Beginners(.*)", "XYZ.com"));
}
}