拆分

Lists.partition 将list集合按指定长度进行切分,返回新的List>集合

  1. <dependency>
  2. <groupId>com.google.guava</groupId>
  3. <artifactId>guava</artifactId>
  4. <version>21.0</version>
  5. </dependency>
  1. List<String> list = new ArrayList<>();
  2. list.add("快");
  3. list.add("敲");
  4. list.add("代");
  5. list.add("码");
  6. list.add("去");
  7. // 将集合list按照 2 个元素一份进行划分
  8. List<List<String>> partition = Lists.partition(list, 2);

快速生成list

Lists.newArrayList()

  1. List<Integer> numList = Lists.newArrayList(1, 2, 3, 4, 5, 6, 7, 8);