我想要编写的代码将字符串拆分为不同的子字符串,每个字符串包含3个字符 并将它们分配给字符串数组,例如字符串“abcdefg”可以是“abc”,“bcd “,”cde“,”efg“,并将它们分配给一个字符串数组。我有以下的代码这是越来越错误:数组越界错误
String[] words = new String[] {};
String sequence = "abcdefg";
int i;
for(i = 0; i <= sequence.length()-3; i++) {
words[i] = sequence.substring(i, 3+i);
System.out.println(words[i]);
}
它的工作原理,谢谢很多 – 2014-11-03 08:31:29