在 Java 中将子字符串提取为字符数组
若要在 Java 中将子字符串提取为字符数组,请使用 getChars() 方法。
假设以下内容为我们的字符串和字符数组。
String str = "World is not enough!"; char[] chArr = new char[10];
现在,使用 getChars() 方法提取子字符串。
str.getChars(13, 19, chArr, 0);
上面的子字符串是一个字符数组,可以像下面完整示例中所示那样显示 −
示例
public class Demo {
public static void main(String[] args) {
String str = "World is not enough!";
char[] chArr = new char[10];
str.getChars(13, 19, chArr, 0);
for(char res: chArr) {
System.out.println(res);
}
}
}输出
e n o u g h
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP