在编程时通常会遇到一些问题,有时候是不知所措,有时候是解决方案不够优雅,本篇旨在记录编程过程中一些个人想不到的稍微优雅一点的解决方案,方案来源均来自互联网。
List使用subList实现分页获取
1 2 3 4 5 6 7 8 9 10
| int subSize = 1000; int subCount = list.size(); int subPageTotal = (subCount / subSize) + ((subCount % subSize > 0) ? 1 : 0);
for (int i = 0, len = subPageTotal - 1; i <= len; i++) { int fromIndex = i * subSize; int toIndex = ((i == len) ? subCount : ((i + 1) * subSize)); List<String> strings = list.subList(fromIndex, toIndex); }
|
ArrayList和数组int[]的相互转化
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| int[] data = {4, 5, 3, 6, 2, 5, 1};
List<Integer> list1 = Arrays.stream(data).boxed().collect(Collectors.toList());
Integer[] integers1 = Arrays.stream(data).boxed().toArray(Integer[]::new);
Integer[] integers2 = list1.toArray(new Integer[0]);
int[] arr1 = list1.stream().mapToInt(Integer::valueOf).toArray();
int[] arr2 = Arrays.stream(integers1).mapToInt(Integer::valueOf).toArray();
List<Integer> list2 = Arrays.asList(integers1);
String[] strings1 = {"a", "b", "c"};
List<String> list3 = Arrays.asList(strings1);
String[] strings2 = list3.toArray(new String[0]);
|
镜像地址
https://www.cnblogs.com/coderzhw/p/11094326.html