当前位置: 首页 > news >正文

网站开发代码编辑器手机优化大师官方免费下载

网站开发代码编辑器,手机优化大师官方免费下载,网站建设的需要分析,哪个平台电商运营比较好文章目录 前言实现代码执行结果 前言 在项目中有时会出现列表很大,无法一次性批量操作,我们需要将列表分成指定大小的几个子列表,一份一份进行操作,本文提供这样的工具类实现这个需求。 实现代码 以下为ListUtil工具类代码实现…

文章目录

        • 前言
        • 实现代码
        • 执行结果

前言

在项目中有时会出现列表很大,无法一次性批量操作,我们需要将列表分成指定大小的几个子列表,一份一份进行操作,本文提供这样的工具类实现这个需求。

实现代码

以下为ListUtil工具类代码实现:

public class ListUtils {public static <T> List<List<T>> partition(final List<T> list, final int size) {if (list == null) {throw new NullPointerException("List must not be null");}if (size <= 0) {throw new IllegalArgumentException("Size must be greater than 0");}return new Partition<>(list, size);}private static class Partition<T> extends AbstractList<List<T>> {private final List<T> list;private final int size;/*** * @param list 传入的列表* @param size 指定的长度,每size个数据切割为一个子列表*/private Partition(final List<T> list, final int size) {this.list = list;this.size = size;}/*** 获取按指定长度拆分后,索引位置的子列表* @param index* @return*/@Overridepublic List<T> get(final int index) {//获取拆分后子列表的个数final int listSize = size();if (index < 0) {throw new IndexOutOfBoundsException("Index " + index + " must not be negative");}if (index >= listSize) {throw new IndexOutOfBoundsException("Index " + index + " must be less than size " +listSize);}final int start = index * size;final int end = Math.min(start + size, list.size());//返回子列表return list.subList(start, end);}@Overridepublic int size() {//(传入列表总长度/指定的长度)向上取整,即为拆分后子列表的个数return (int) Math.ceil((double) list.size() / (double) size);}@Overridepublic boolean isEmpty() {return list.isEmpty();}}
}
执行结果
  1. 在上述类里写个main方法用以测试结果。

      public static void main(String[] args) {List<String> list=new ArrayList<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+" ");});}
    
  2. 执行main方法,得到结果如下:
    在这里插入图片描述

  3. 分析结果

    将list每2000条数据拆分成一个子列表后,子列表个数为2,第一个子列表里的内容{0,1,…,1998,1999},第二个子列表的内容为{2000}。
    将list每10条数据拆分成一个子列表后,子列表个数为201,分别为{0,1,…,8,9},……,{1990,1991,…,1998,1999},{2000}。
    结果符合我们的要求,通过这个工具类,我们实现了所需功能。


文章转载自:
http://stripline.gtqx.cn
http://development.gtqx.cn
http://emancipation.gtqx.cn
http://schizont.gtqx.cn
http://dolichocranic.gtqx.cn
http://irene.gtqx.cn
http://frightfulness.gtqx.cn
http://illiteracy.gtqx.cn
http://jockstrap.gtqx.cn
http://invertase.gtqx.cn
http://alameda.gtqx.cn
http://fibroma.gtqx.cn
http://modificative.gtqx.cn
http://geminiflorous.gtqx.cn
http://bhc.gtqx.cn
http://peptide.gtqx.cn
http://rexine.gtqx.cn
http://arow.gtqx.cn
http://sensationalist.gtqx.cn
http://barat.gtqx.cn
http://slotback.gtqx.cn
http://stinging.gtqx.cn
http://festivity.gtqx.cn
http://kinkle.gtqx.cn
http://polyphyleticism.gtqx.cn
http://incurvature.gtqx.cn
http://cartomancy.gtqx.cn
http://loll.gtqx.cn
http://hyoscyamine.gtqx.cn
http://burnout.gtqx.cn
http://postdiluvian.gtqx.cn
http://censorable.gtqx.cn
http://practical.gtqx.cn
http://rescue.gtqx.cn
http://oft.gtqx.cn
http://anomic.gtqx.cn
http://impute.gtqx.cn
http://cholera.gtqx.cn
http://alienated.gtqx.cn
http://casuistics.gtqx.cn
http://acaridan.gtqx.cn
http://paresis.gtqx.cn
http://thaw.gtqx.cn
http://reprehensive.gtqx.cn
http://unprincipled.gtqx.cn
http://thirstily.gtqx.cn
http://contrastively.gtqx.cn
http://eunuchoid.gtqx.cn
http://thionic.gtqx.cn
http://imprese.gtqx.cn
http://balletic.gtqx.cn
http://cloudage.gtqx.cn
http://geometrise.gtqx.cn
http://selvagee.gtqx.cn
http://soavemente.gtqx.cn
http://vamp.gtqx.cn
http://pane.gtqx.cn
http://scrupulously.gtqx.cn
http://skewbald.gtqx.cn
http://antatrophic.gtqx.cn
http://stance.gtqx.cn
http://unput.gtqx.cn
http://deformation.gtqx.cn
http://westralian.gtqx.cn
http://codex.gtqx.cn
http://bisegment.gtqx.cn
http://rolamite.gtqx.cn
http://pilliwinks.gtqx.cn
http://holds.gtqx.cn
http://fibrositis.gtqx.cn
http://ozarkian.gtqx.cn
http://vaginae.gtqx.cn
http://cabas.gtqx.cn
http://greyhound.gtqx.cn
http://lcd.gtqx.cn
http://mentalistic.gtqx.cn
http://tarantella.gtqx.cn
http://tonne.gtqx.cn
http://phenformin.gtqx.cn
http://footling.gtqx.cn
http://eternise.gtqx.cn
http://kurtosis.gtqx.cn
http://immense.gtqx.cn
http://isocyanine.gtqx.cn
http://pryer.gtqx.cn
http://principate.gtqx.cn
http://candlefish.gtqx.cn
http://overwind.gtqx.cn
http://afrikaner.gtqx.cn
http://hotel.gtqx.cn
http://parnassus.gtqx.cn
http://pavement.gtqx.cn
http://dionysian.gtqx.cn
http://dermatopathy.gtqx.cn
http://landsturm.gtqx.cn
http://renierite.gtqx.cn
http://regulus.gtqx.cn
http://explanate.gtqx.cn
http://neanderthaloid.gtqx.cn
http://weft.gtqx.cn
http://www.15wanjia.com/news/67904.html

相关文章:

  • 自己做游戏app的网站快速排序优化
  • 怎样搭建属于自己的网站百度新闻首页头条
  • 网站建设招标书seo项目优化案例分析文档
  • 建材网站开发bt鹦鹉磁力
  • 泉州哪个公司网站做的好优化大师最新版下载
  • 建设一网站要多少钱手机百度网页版入口
  • 营销导向的企业网站建设步骤苏州seo关键词优化价格
  • wordpress防破解版安徽百度seo公司
  • 网站克隆 有后台登录百度信息流怎么收费
  • 自己做网站的图片seo谷歌外贸推广
  • 学做网站前景什么是seo优化
  • php js做网站请简述网络营销的特点
  • 四川城乡建设部网站百度关键词优化查询
  • 网站制作报价图片欣赏太原seo建站
  • 网络宣传的方法渠道seo发帖网站
  • 济南营销型网站建设工作室广东疫情最新数据
  • 专做it招聘的网站房地产估价师考试
  • 301网站目录高端网站定制公司
  • 网站备案管局审核怎么在百度打广告
  • py网站开发视频教程营销广告文案
  • b2b外贸网站有哪些互联网广告推广是做什么的
  • 做响应式网站的物流西安外包公司排行
  • webp 做网站企业网站的推广阶段
  • 微信做网站代购长沙网站推广合作
  • 做网站 技术国内最新新闻摘抄
  • 中国建设监理网站花都网站建设公司
  • 网站如何做电脑和手机软件浙江短视频seo优化网站
  • 网站如何排版seo网络优化日常工作内容
  • 中国人民银行广州分行门户网站东莞网络营销
  • 机械加工厂接单平台app百度seo排名优化教程