Null

  1. import org.apache.commons.collections4.CollectionUtils;
  2. CollectionUtils.isNotEmpty(list);
  3. !(list == null || list.isEmpty());

String字符串

  1. // str = "2,5,8,7";
  2. String str = "2,5,8,7";
  3. List<Integer> idList = StringUtil.stringToList(str,",");

equals

  1. Objects.equals(name, thisName);

String

  1. List<String> list = new ArrayList<String>();
  2. list.add("1");
  3. list.add("2");
  4. list.add("3");
  5. String result = Joiner.on("-").join(list);

Map

实体转MAP

  1. public static void Test() {
  2. List<Student> list = new ArrayList<>();
  3. list.add(new Student(1, "key1", "张"));
  4. list.add(new Student(2, "key2", "李"));
  5. Map<String, String> result = list.stream()
  6. .collect(Collectors.toMap(student -> student.getKey(), Student::getName));
  7. // result: {key1=zhangsan, key2=lisi}
  8. }

Consumer

  1. Consumer<String> consumer = (str) -> System.out.println(str);
  2. consumer.accept("Hello Lambda!");
  3. consumer.notify();

Function

  1. Function<String, String> fun = (x) -> x + "/";
  2. fun.apply("s");

DemoStringBuilder Optional

  1. /**
  2. * 获取 地图服务的名称 和 用户角色的名称
  3. *
  4. * @param sysMapAuthEntity
  5. * @return serverName, roleName
  6. */
  7. private String[] getServerNameAndRoleName(SysMapAuthEntity sysMapAuthEntity) {
  8. MapServerEntity mapServerEntity = mapServerService
  9. .getById(sysMapAuthEntity.getGisMapServerId());
  10. StringBuilder sb = new StringBuilder();
  11. Optional<MapServerEntity> serverOpt = Optional.ofNullable(mapServerEntity);
  12. Consumer<String> slash = x -> sb.append(x + "/");
  13. serverOpt.map(MapServerEntity::getSvcFolder).ifPresent(slash);
  14. sb.append(mapServerEntity.getSvcName());
  15. // _folder_serverName
  16. String roleName = "_" + sb.toString().replace("/", "_");
  17. //根据代码获取地图服务器
  18. return new String[]{sb.toString(), roleName};
  19. }

QueryWrapper

  1. List<User> userList = this.userService.list(
  2. new QueryWrapper<User>()
  3. .lambda()
  4. .ge(User::getAge, 18)
  5. .likeLeft(User::getName, "ext")
  6. .eq(User::getEmail, "ext@baomidou.com")
  7. ...
  8. );