摘要:java通过String类中的getChars方法得到字符串的指定位置的字符串放置字符数组。以下是我们为大家整理的,相信大家阅读完后肯定有了自己的选择吧。
java通过String类中的getChars方法得到字符串的指定位置的字符串放置字符数组
public class getChars { public static void main(String args[]) { String s = "This is a getChars method."; int start = 10;//第一个字符的位置(索引)为0,10代表第11个字符位置 int end = 18;//第19个字符位置 char buf[] = new char[end - start]; s.getChars(start, end, buf, 0);//得到从buf数组的第0位开始数第10位到18位的字符串 System.out.println(buf); } }