我试图在网上搜索来解决这个问题,但我没有找到任何东西。
我编写了以下抽象代码来解释我的要求:
String text = "how are you?";
String[] textArray= text.splitByNumber(4); //this method is what I'm asking
textArray[0]; //it contains "how "
textArray[1]; //it contains "are "
textArray[2]; //it contains "you?"
splitByNumber 方法每 4 个字符分割字符串“text”。我怎样才能创建这个方法?
非常感谢
我认为他想要的是将一个字符串分割成大小为 4 的子字符串。然后我会在循环中执行此操作:
List<String> strings = new ArrayList<String>();
int index = 0;
while (index < text.length()) {
strings.add(text.substring(index, Math.min(index + 4,text.length())));
index += 4;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)