String数组自定义参数个数拆分多个子数组
程序员文章站
2022-07-15 12:14:09
...
public static void main(String[] args) {
String[] strs = {"17:51","17:57","18:02","18:06","18:12","18:17","18:22","18:27","18:32","18:37","18:41","18:47","18:52","18:57","19:02","19:07","19:12","19:17","19:22","19:27","19:32","19:37","19:42","19:47","19:52","19:57","20:02","20:07","20:12","20:17","20:22","20:37","20:42","20:47","20:52","20:57","21:02","21:07","21:12","21:17","21:22","21:27","21:32","21:37","21:42","21:47","21:52","21:57","22:02","22:07","22:12","22:17","22:22","22:27","22:32","22:37","22:42","22:47","22:52","22:57","23:02","23:07","23:12","23:18","23:23","23:27","23:32","23:37","23:42","23:47","23:52","00:02","00:07","00:12","00:18","00:22","00:28","00:33","00:38","00:43","00:48","00:53","00:58","01:03","01:08","01:13","01:18","01:23","01:28","01:33","01:38","01:43","01:48","01:53","01:58"};
System.out.println(strs.length);
int splitSize = 6;
List<String> datas = Arrays.asList(strs);
if (datas == null || splitSize < 1) {
}
int totalSize = datas.size();
int count = (totalSize % splitSize == 0) ?
(totalSize / splitSize) : (totalSize/splitSize+1);
List<List<String>> rows = new ArrayList<>();
for (int i = 0; i < count;i++) {
List<String> cols = datas.subList(i * splitSize,
(i == count - 1) ? totalSize : splitSize * (i + 1));
rows.add(cols);
System.out.println(cols);
}
}
上一篇: Web Service