更新时间:2022-06-09 05:21:49
您也可以使用可变的 StringBuilder
类.
You can also use the StringBuilder
class which is mutable.
StringBuilder sb = new StringBuilder(inputString);
它有方法 deleteCharAt()
,以及许多其他的mutator方法.
It has the method deleteCharAt()
, along with many other mutator methods.
只需删除需要删除的字符,然后得到如下结果:
Just delete the characters that you need to delete and then get the result as follows:
String resultString = sb.toString();
这避免了创建不必要的字符串对象.
This avoids creation of unnecessary string objects.