如何从字符串中移除特定字符。


以下示例展示了如何借助 removeCharAt(string, position) 方法从字符串特定位置移除字符。

示例

在线示例

public class Sample {
   public static void main(String args[]) {
      String str = "this is Java";
      System.out.println(removeCharAt(str, 3));
   }
   public static String removeCharAt(String s, int pos) {
      return s.substring(0, pos) + s.substring(pos + 1);
   }
}

输出

this is Java

更新日期:2020 年 6 月 18 日

242 次浏览

开拓你的事业

完成课程获取认证

开始
广告