com.google.guava
guava
27.0.1-jre
org.projectlombok
lombok
package com.lucifer.guava.collections;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.ArrayList;
import java.util.List;
/**
* author: lucifer
* date: 2020/5/27 10:20
* description: TODO
*/
public class test4 {
public static void main(String[] args) {
List users1 = new ArrayList<>();
users1.add(new User1("a", 20));
users1.add(new User1("b", 21));
users1.add(new User1("c", 22));
List list = new ArrayList<>();
list.add(1);
list.add(2);
/**
* 1、cartesianProduct
* Lists.cartesianProduct:通过从每个给定列表中依次选择一个元素,返回可以形成的所有可能列表;列表的“ n元笛卡尔积 ”。
*/
List> cartesianProduct = Lists.cartesianProduct(users1, list);
System.out.println("Lists.cartesianProduct:===============cartesianProduct:" + cartesianProduct);
/**
* 2、reverse(List list)
* 返回指定列表的反向视图。
*/
List reverse = Lists.reverse(list);
System.out.println("Lists.reverse=============revers:" + reverse);
/**
* 3、transform(List fromList, Function function)
* 返回适用function于的每个元素的列表fromList。
*/
List
控制台打印:
Lists.cartesianProduct:===============cartesianProduct:[[User1(userName=a, age=20), 1], [User1(userName=a, age=20), 2], [User1(userName=b, age=21), 1], [User1(userName=b, age=21), 2], [User1(userName=c, age=22), 1], [User1(userName=c, age=22), 2]]
Lists.reverse=============revers:[2, 1]
Lists.transform:================transform:[a, b, c]
Lists.partition:===========partition:[[User1(userName=a, age=20), User1(userName=b, age=21)], [User1(userName=c, age=22)]]
Lists.charactersOf(String string)==================[张, 三, 在, 学, g, u, a, v, a]
Lists.charactersOf(CharSequence sequence)==================[张, 三, 在, 学, g, u, a, v, a]