publicclassListUtils{publicstatic<T>List<List<T>>partition(finalList<T> list,finalint size){if(list ==null){thrownewNullPointerException("List must not be null");}if(size <=0){thrownewIllegalArgumentException("Size must be greater than 0");}returnnewPartition<>(list, size);}privatestaticclassPartition<T>extendsAbstractList<List<T>>{privatefinalList<T> list;privatefinalint size;/*** * @param list 传入的列表* @param size 指定的长度,每size个数据切割为一个子列表*/privatePartition(finalList<T> list,finalint size){this.list = list;this.size = size;}/*** 获取按指定长度拆分后,索引位置的子列表* @param index* @return*/@OverridepublicList<T>get(finalint index){//获取拆分后子列表的个数finalint listSize =size();if(index <0){thrownewIndexOutOfBoundsException("Index "+ index +" must not be negative");}if(index >= listSize){thrownewIndexOutOfBoundsException("Index "+ index +" must be less than size "+listSize);}finalint start = index * size;finalint end =Math.min(start + size, list.size());//返回子列表return list.subList(start, end);}@Overridepublicintsize(){//(传入列表总长度/指定的长度)向上取整,即为拆分后子列表的个数return(int)Math.ceil((double) list.size()/(double) size);}@OverridepublicbooleanisEmpty(){return list.isEmpty();}}publicstaticvoidmain(String[] args){List<String> list=newArrayList<String>();for(int i =0; i <=2000; i++){list.add(i+"");}//将list每2000条数据拆分成一个子列表List<List<String>> partition =ListUtils.partition(list,2000);System.out.println("将list每2000条数据拆分成一个子列表:");System.out.println("子列表个数:"+partition.size());System.out.println("第二个子列表的内容:");partition.get(1).forEach(System.out::print);System.out.println("-------------------------------------------------------");System.out.println("将list每10条数据拆分成一个子列表:");List<List<String>> partition1 =ListUtils.partition(list,10);System.out.println("子列表个数:"+partition1.size());System.out.println("第三个子列表的内容:");partition1.get(2).forEach(s ->{System.out.print(s+" ");});}}
领先的开源对话 AI 工具包 NVIDIA NeMo宣布推出 Parakeet ASR 模型系列,这是一系列最先进的自动语音识别(ASR)模型,能够以出色的准确性转录英语口语。Parakeet ASR 模型与 Suno.ai 合作开发,是语音识别领域的一大突破&…