如果你的分词规则是在一个字符串的开头和结尾加上"_",然后两个字符一分的话,代码可以这样写:
import java.util.ArrayList;
import java.util.List;
public class Participle
{
private static final String HEAD_END_STR = "_";
private static final int PARTICIPLE_LENGTH = 2;
public static void main(String[] args)
{
String exampleWord = "计算机";
exampleWord = "_" + exampleWord + "_";
int length = exampleWord.length();
List<String> result = new ArrayList<String>();
for (int i = 0; i < length - 1; i++)
{
String str = exampleWord.substring(i, i + PARTICIPLE_LENGTH);
result.add(str);
}
System.out.println(result);
}
}
输出结果:_计, 计算, 算机, 机_