比如我有个字符串String = "The possible problem is, How is that possible" 我想判断比如说最后的字符是不是possible,如果是,我想把它替换成impossible。 因为如果我使用replaceAll,会把前面的possible也换掉……对于这个有没有什么解决方案呢? 谢谢
String s = "The possible problem is, How is that possible"; if(s.endsWith("possible")){ String s1 = s.substring(0, s.lastIndexOf("possible")); s = s1 + "impossible"; } System.out.println(s);