高分悬赏,缺C币的看下,Java语言关于数组的分割怎么实现

怎么把数组分割成2个数组,每个数组的长度是原始数组的1/2
要完整的代码和注释。

https://blog.csdn.net/qq_34926773/article/details/94437175

List<String> list = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            list.add("China"+i);
        }

        CommUtil<String> util = new CommUtil<String>();
        List<List<String>> resultList = util.subListBySegment(list, 2);
        for (int i = 0; i < resultList.size(); i++) {
            List<String> tempList = resultList.get(i);
            for (int j = 0; j < tempList.size(); j++) {
                System.out.print(tempList.get(j));
            }
        }
public class CommUtil<T> {
    public List<List<T>> subListBySegment(List<T> data, int segments) {

        List<List<T>> result = new ArrayList<>();

        int size = data.size();// 数据长度

        if (size > 0 && segments > 0) {// segments == 0 ,不需要分隔

            int count = size / segments;// 每段数量

            List<T> cutList = null;// 每段List

            for (int i = 0; i < segments; i++) {
                if (i == segments - 1) {
                    cutList = data.subList(count * i, size);
                } else {
                    cutList = data.subList(count * i, count * (i + 1));
                }
                result.add(cutList);
            }
        } else {
            result.add(data);
        }
        return result;
    }

    public List<List<T>> subListByCount(List<T> data, int count) {

        List<List<T>> result = new ArrayList<>();

        int size = data.size();// 数据长度

        if (size > 0 && count > 0) {

            int segments = size / count;// 商
            /**
             * 1.整除,  即分隔为segments     段
             * 2.除不尽,即分隔为segments + 1 段
             */
            segments = size % count == 0 ? segments : segments + 1; // 段数

            List<T> cutList = null;// 每段List

            for (int i = 0; i < segments; i++) {
                if (i == segments - 1) {
                    cutList = data.subList(count * i, size);
                } else {
                    cutList = data.subList(count * i, count * (i + 1));
                }
                result.add(cutList);
            }
        } else {
            result.add(data);
        }
        return result;
    }
}

public List splitArray(T[] arr,Class clazz){
if(null == arr || arr.length == 0){
return new ArrayList<>();
}
int length = arr.length;
int subLength = length / 2;
List result = new ArrayList<>();
T[] subArr1 = (T[]) Array.newInstance(clazz,subLength); //子数组1
T[] subArr2 = (T[]) Array.newInstance(clazz,length - subLength); //子数组2
result.add(subArr1);
result.add(subArr2);
for(int i = 0; i < length; i++){
if(i < subLength){ //给子数组1赋值
subArr1[i] = arr[i];
}else{ //给子数组2赋值
subArr2[i - subLength] = arr[i];
}
}
return result;
}
public static void main(String[] args) {
Integer[] arr = {1,2,3,4,5,6,7};
List integers = new StringTest().splitArray(arr, Integer.class);
System.out.println(Arrays.toString(integers.get(0)));
System.out.println(Arrays.toString(integers.get(1)));
}