`
luchangbin_66
  • 浏览: 23571 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Guava学习笔记-Lists

    博客分类:
  • Java
 
阅读更多

学习Elastic-Job - 分布式定时任务框架

源码查看多线程分片操作时工具类采用集合类Google Guava包进行list的分组操作

 

//均分为每个子list大小为2的嵌套list
Lists.partition() 

 

    可利用此工具分组list操作

 

package com.dangdang.ddframe;

import java.util.ArrayList;
import java.util.List;

import com.google.common.collect.Lists;

public class Test {

    class Foo {

        private int id;

        private String name;

        public Foo(int id, String name) {
            this.id = id;
            this.name = name;
        }

        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        @Override
        public String toString() {
            return "Foo [id=" + id + ", name=" + name + "]";
        }

    }

    public static void main(String[] args) {

        List<Foo> data = new ArrayList<Foo>();
        for (int i = 0; i < 20; i++) {
            Test.Foo f = new Test().new Foo(i, i + "名称");
            data.add(f);
        }

        List<List<Foo>> splitData = Lists.partition(data, data.size() / 10);
        System.out.println("分组数量:" + data.size() / 10);
        System.out.println(splitData.size());
        for (int i = 0; i < splitData.size(); i++) {
            System.out.println("分组:" + i);
            // List<Foo> s = splitData.get(i);
            System.out.println(splitData.get(i).toString());
        }

    }
}

 

分享到:
评论

相关推荐

    guava-30.0-jre-API文档-中文版.zip

    赠送jar包:guava-30.0-jre.jar; 赠送原API文档:guava-30.0-jre-javadoc.jar; 赠送源代码:guava-30.0-jre-sources.jar; 赠送Maven依赖信息文件:guava-30.0-jre.pom; 包含翻译后的API文档:guava-30.0-jre-...

    guava-27.0.1-jre-API文档-中文版.zip

    赠送jar包:guava-27.0.1-jre.jar; 赠送原API文档:guava-27.0.1-jre-javadoc.jar; 赠送源代码:guava-27.0.1-jre-sources.jar; 赠送Maven依赖信息文件:guava-27.0.1-jre.pom; 包含翻译后的API文档:guava-...

    guava-25.0-jre-API文档-中文版.zip

    赠送jar包:guava-25.0-jre.jar; 赠送原API文档:guava-25.0-jre-javadoc.jar; 赠送源代码:guava-25.0-jre-sources.jar; 赠送Maven依赖信息文件:guava-25.0-jre.pom; 包含翻译后的API文档:guava-25.0-jre-...

    guava-28.2-jre-API文档-中文版.zip

    赠送jar包:guava-28.2-jre.jar; 赠送原API文档:guava-28.2-jre-javadoc.jar; 赠送源代码:guava-28.2-jre-sources.jar; 赠送Maven依赖信息文件:guava-28.2-jre.pom; 包含翻译后的API文档:guava-28.2-jre-...

    guava-27.0-jre.jar

    guava-27.0-jre.jar

    guava-11.0.2-API文档-中文版.zip

    赠送jar包:guava-11.0.2.jar; 赠送原API文档:guava-11.0.2-javadoc.jar; 赠送源代码:guava-11.0.2-sources.jar; 赠送Maven依赖信息文件:guava-11.0.2.pom; 包含翻译后的API文档:guava-11.0.2-javadoc-API...

    guava-29.0-jre-API文档-中英对照版.zip

    赠送jar包:guava-29.0-jre.jar; 赠送原API文档:guava-29.0-jre-javadoc.jar; 赠送源代码:guava-29.0-jre-sources.jar; 赠送Maven依赖信息文件:guava-29.0-jre.pom; 包含翻译后的API文档:guava-29.0-jre-...

    guava-20.0-API文档-中文版.zip

    赠送jar包:guava-20.0.jar; 赠送原API文档:guava-20.0-javadoc.jar; 赠送源代码:guava-20.0-sources.jar; 赠送Maven依赖信息文件:guava-20.0.pom; 包含翻译后的API文档:guava-20.0-javadoc-API文档-中文...

    guava-27.1-jre.jar

    guava-27.1-jre

    guava-28.2-android.jar

    guava-28.2-android.jar

    最新版 guava-30.1-jre.jar

    最新版 guava-30.1-jre.jar

    guava-28.2-jre-API文档-中英对照版.zip

    赠送jar包:guava-28.2-jre.jar; 赠送原API文档:guava-28.2-jre-javadoc.jar; 赠送源代码:guava-28.2-jre-sources.jar; 赠送Maven依赖信息文件:guava-28.2-jre.pom; 包含翻译后的API文档:guava-28.2-jre-...

    guava-29.0-jre-API文档-中文版.zip

    赠送jar包:guava-29.0-jre.jar; 赠送原API文档:guava-29.0-jre-javadoc.jar; 赠送源代码:guava-29.0-jre-sources.jar; 赠送Maven依赖信息文件:guava-29.0-jre.pom; 包含翻译后的API文档:guava-29.0-jre-...

    guava-26.0-android-API文档-中文版.zip

    赠送jar包:guava-26.0-android.jar; 赠送原API文档:guava-26.0-android-javadoc.jar; 赠送源代码:guava-26.0-android-sources.jar; 赠送Maven依赖信息文件:guava-26.0-android.pom; 包含翻译后的API文档:...

    guava-24.1-jre-API文档-中英对照版.zip

    赠送jar包:guava-24.1-jre.jar; 赠送原API文档:guava-24.1-jre-javadoc.jar; 赠送源代码:guava-24.1-jre-sources.jar; 赠送Maven依赖信息文件:guava-24.1-jre.pom; 包含翻译后的API文档:guava-24.1-jre-...

    guava-20.0-API文档-中英对照版.zip

    赠送jar包:guava-20.0.jar; 赠送原API文档:guava-20.0-javadoc.jar; 赠送源代码:guava-20.0-sources.jar; 赠送Maven依赖信息文件:guava-20.0.pom; 包含翻译后的API文档:guava-20.0-javadoc-API文档-中文...

    guava-23.0-API文档-中文版.zip

    赠送jar包:guava-23.0.jar; 赠送原API文档:guava-23.0-javadoc.jar; 赠送源代码:guava-23.0-sources.jar; 赠送Maven依赖信息文件:guava-23.0.pom; 包含翻译后的API文档:guava-23.0-javadoc-API文档-中文...

    guava-18.0-API文档-中文版.zip

    赠送jar包:guava-18.0.jar; 赠送原API文档:guava-18.0-javadoc.jar; 赠送源代码:guava-18.0-sources.jar; 包含翻译后的API文档:guava-18.0-javadoc-API文档-中文(简体)版.zip 对应Maven信息:groupId:...

    guava-28.0-android-API文档-中文版.zip

    赠送jar包:guava-28.0-android.jar; 赠送原API文档:guava-28.0-android-javadoc.jar; 赠送源代码:guava-28.0-android-sources.jar; 赠送Maven依赖信息文件:guava-28.0-android.pom; 包含翻译后的API文档:...

    guava-26.0-jre.zip

    Guava是Google为Java平台设计并维护的一个开源库,它提供了许多高级功能和实用工具,极大地增强了Java开发的效率和代码质量。Guava 26.0-jre版本是针对Java运行时环境(JRE)优化的一个特定版本,旨在更好地支持Java...

Global site tag (gtag.js) - Google Analytics