[Solved] Replace String variable with exact string


If I understand your question, you could use String.replace(CharSequence, CharSequence) like

String str="abcd";
String rep="cd";
String nv = "kj";
str = str.replace(rep, nv); // <-- old, new
System.out.println(str);

Output is (the requested)

abkj

1

solved Replace String variable with exact string