Java工具类
- 剔除字符串的空格
- 没有泛型的List集合判断为空
- 集合判空
- list != null && list.size() > 0
- CollUtil.isEmpty(mdpCompensationStandarList)
- CollectionUtils.isNotEmpty()
- 字符串判空
- StringUtils.isEmpty(mdpThreePhaseInfoDTOList.get(i).getTreatmentMethod())
- !CommonUtils.isEmpty(strPageNo)
- StrUtil.isNotBlank()
- !StringUtils.nullOrBlank(resultStr)
- String str = "1";(Controller接收)
- System.out.println(StringUtils.isNotEmpty(str) ? "不空" : "空");
- int类型判空(Controller接收)
- pointsRecordParameter.setType(null != pointsQueryDto.getType() ? pointsQueryDto.getType() : 0);
- 时间类型判空(Controller接收)
- if (null != pointsQueryDto.getStartTime()) pointsRecordParameter.setStartTime(pointsQueryDto.getStartTime());
- 数组判断是否为空
- criticalPointJsonArray.isEmpty()
- 可添加多个对象到集合
- 实体转换 把第一个对象转换到第二个对象里面 后续操作第二个对象
- MsExpertOrderCopy data = new MsExpertOrderCopy();
- BeanUtil.copyProperties(params, data);
- 生成UUID 添加逻辑主键
- String id = IdUtil.simpleUUID();
- 集合赋值
- 把第一个参数集合的对应值 赋值到 第二个集合中 以后操作第二个集合
- BeanUtil.copyProperties(request, msExpertOrderCopy);7
- 取出第一个值
- 北京-BJ
- deptld.split("-")[0] 北京
- 自定义异常
- //Exception in thread "main" java.lang.RuntimeException: 权限不足!
- throw new RuntimeException("权限不足!");
- 创建一个新的 Map
- Map<String,String> map= Maps.newHashMap();
- 数组转集合
- String key[] = {"1", "2", "3", "4"};
- System.out.println("集合" + CollectionUtils.arrayToList(key));
- List提取某个字段转换成List
- List userIds = list.stream().map(Student::getName).collect(Collectors.toList());
- or
- List userIds = list.stream().map(student -> student.getName()).collect(Collectors.toList());
- 三元运算符 ----》替换
- String re = "222";
- re = re != null ? re.replaceAll("111", "") : null;
- 创建List元素
- 创建不可变List的单个元素
- List ids = Collections.singletonList("CATJ0D000206");
- 创建可变List元素
- List ids = Arrays.asList("CATJ0D000206");
- 判断是否是某个类型
- 左边是待判断的,右边是你设置的类型
- System.out.println(ids instanceof List)
- 强转为Object类型
- entries.getValue():返回的是Object类型
- 所以需要把它强制转换为Object类型输出
- Arrays.toString((Object[]) entries.getValue())
- Map Foreach循环
- map.forEach((k, v) -> System.out.println(k + ":" + v));
- 异常打印堆栈信息
- 创建空的List
- 创建空的Map
- 字符串判断是否相等。
- Objects.equals("Char",Char);
原文地址:https://www.cnblogs.com/Twittery/p/14971281.html