我的字符串是
String s="agshshdhdbdhsusjdidjdjdjfjfjrywoetdmfhd";
我们必须通过
从0-4
,5-8
,9-12
等处拆分出来...
答案 0 :(得分:0)
这是示例代码。 希望能帮助到你。
public static void main(String[] args) {
String s= "agshshdhdbdhsusjdidjdjdjfjfjrywoetdmfhd";
List<String> list = splitIntoEqualPartition(s, 4);
for (String a: list) {
System.out.println(a);
}
}
public static List<String> splitIntoEqualPartition(String str, int partitionSize) {
if (str == null) {
return null;
}
List<String> partitions = new ArrayList<>();
while (str.length() >= partitionSize) {
partitions.add(str.substring(0, partitionSize));
str = str.substring(partitionSize);
}
if (str.length() > 0) {
partitions.add(str);
}
return partitions;
}