最简单的可以用String.replaceFirst("great ","");
也可以用正则表达式
//待处理字符串
String ori = "James is great super smashing great";
//需要替换的字符串
String def = "great ";
Pattern pattern = Pattern.compile(def);
//找到第一个匹配的字符串
Matcher matcher = pattern.matcher(ori);
//将第一个匹配的字符串替换成空字符串
String s = matcher.replaceFirst("");
//
System.out.println(s);
String ori="James is great super smashing great";
String def="great ";
if(ori.indexOf(def)!=-1){
System.out.println(ori.replace(def,""));
}
// 得到 assertEquals("James is super smashing great")
str1.replaceFirst(str2+" ", "")