欢迎您 本站地址:  
返回首页   返回编程教学   少儿名著书籍  cosplay美女  合集  明朝历史  海鲜篇  学习jQueryUI  学习Lua  学习SQLite 

Java 实例 - 删除字符串中的一个字符

Java 实例 Java 实例

以下实例中我们通过字符串函数 substring() 函数来删除字符串中的一个字符,我们将功能封装在 removeCharAt 函数中。

实例代码如下:

Main.java 文件

public class Main { 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); } }

以上代码实例输出结果为:

thi is Java

Java 实例 Java 实例

小库提示

扫描下方二维码,访问手机版。