侧边栏壁纸
博主头像
侯秀荣

贪婪和恐惧是人性的两大弱点,
人类几万年,人性也没进步1厘米。

  • 累计撰写 172 篇文章
  • 累计收到 3 条评论

常用Java时间处理、guava-Lists分割

2017-11-7 / 0 评论 / 2904 阅读

import com.alibaba.fastjson.JSON;

import com.google.common.collect.Lists;

import com.google.common.primitives.Ints;

import java.util.List;



public static void main(String[] args) {

      long diff = new Date().getTime();

      long system = System.currentTimeMillis();

      long nanoTime = System.nanoTime();

      System.out.println("system  :" + system);

      System.out.println("diff    :" + diff);

      System.out.println("nanoTime:" + nanoTime);



      // google guava-16.0.1.jar

      List countUp = Ints.asList(1, 2, 3, 4, 5,6);

      // [5, 4, 3, 2, 1]

      List countDown = Lists.reverse(countUp);

      System.out.println("countDown:"+JSON.toJSONString(countDown));

      //[[1,2],[3,4],[5,6]]

      List<List<Integer>> parts = Lists.partition(countUp, 2);

      for(List<Integer> subList:parts){

          System.out.println(parts.size()+",subList"+JSON.toJSONString(subList));

      }

      System.out.println("parts    :"+JSON.toJSONString(parts));

}



最后console输出:

system  :1510045212131

diff    :1510045212131

nanoTime:26242702289112

countDown:[6,5,4,3,2,1]

3,subList[1,2]

3,subList[3,4]

3,subList[5,6]

parts    :[[1,2],[3,4],[5,6]]




















评论一下?

OωO
取消