更新时间:2022-06-19 23:22:52
replace
将替换一个字母的所有实例.您需要做的就是使用 substring()
:
replace
will replace all instances of a letter. All you need to do is use substring()
:
public String method(String str) {
if (str != null && str.length() > 0 && str.charAt(str.length() - 1) == 'x') {
str = str.substring(0, str.length() - 1);
}
return str;
}