zoukankan      html  css  js  c++  java
  • Java工具类

    1. 剔除字符串的空格
      • userName.trim();
    2. 没有泛型的List集合判断为空
      • result.isEmpty()
    3. 集合判空
      • list != null && list.size() > 0
      • CollUtil.isEmpty(mdpCompensationStandarList)
      • CollectionUtils.isNotEmpty()
    4. 字符串判空
      • StringUtils.isEmpty(mdpThreePhaseInfoDTOList.get(i).getTreatmentMethod())
      • !CommonUtils.isEmpty(strPageNo)
      • StrUtil.isNotBlank()
      • !StringUtils.nullOrBlank(resultStr)
      • String str = "1";(Controller接收)
        • System.out.println(StringUtils.isNotEmpty(str) ? "不空" : "空");
    5. int类型判空(Controller接收)
    • pointsRecordParameter.setType(null != pointsQueryDto.getType() ? pointsQueryDto.getType() : 0);
    1. 时间类型判空(Controller接收)
    • if (null != pointsQueryDto.getStartTime()) pointsRecordParameter.setStartTime(pointsQueryDto.getStartTime());
    1. 数组判断是否为空
      • criticalPointJsonArray.isEmpty()
    2. 可添加多个对象到集合
      • Collections.addAll();
    3. 实体转换 把第一个对象转换到第二个对象里面 后续操作第二个对象
      • MsExpertOrderCopy data = new MsExpertOrderCopy();
      • BeanUtil.copyProperties(params, data);
    4. 生成UUID 添加逻辑主键
      • String id = IdUtil.simpleUUID();
        • 需导入:hutool-all-5.1.1.jar
    5. 集合赋值
      • 把第一个参数集合的对应值 赋值到 第二个集合中 以后操作第二个集合
        • BeanUtil.copyProperties(request, msExpertOrderCopy);7
    6. 取出第一个值
      • 北京-BJ
      • deptld.split("-")[0] 北京
    7. 自定义异常
      • //Exception in thread "main" java.lang.RuntimeException: 权限不足!
      • throw new RuntimeException("权限不足!");
    8. 创建一个新的 Map
      • Map<String,String> map= Maps.newHashMap();
    9. 数组转集合
      • String key[] = {"1", "2", "3", "4"};
      • System.out.println("集合" + CollectionUtils.arrayToList(key));
    10. List提取某个字段转换成List
      • List userIds = list.stream().map(Student::getName).collect(Collectors.toList());
      • or
      • List userIds = list.stream().map(student -> student.getName()).collect(Collectors.toList());
    11. 三元运算符 ----》替换
      • String re = "222";
      • re = re != null ? re.replaceAll("111", "") : null;
    12. 创建List元素
      • 创建不可变List的单个元素
        • List ids = Collections.singletonList("CATJ0D000206");
      • 创建可变List元素
        • List ids = Arrays.asList("CATJ0D000206");
    13. 判断是否是某个类型
      • 左边是待判断的,右边是你设置的类型
        • System.out.println(ids instanceof List)
    14. 强转为Object类型
      • entries.getValue():返回的是Object类型
      • 所以需要把它强制转换为Object类型输出
      • Arrays.toString((Object[]) entries.getValue())
    15. Map Foreach循环
      • map.forEach((k, v) -> System.out.println(k + ":" + v));
    16. 异常打印堆栈信息
      • e.printStackTrace();
    17. 创建空的List
      • Collections.emptyList();
    18. 创建空的Map
      • Collections.emptyMap();
    19. 字符串判断是否相等。
      • Objects.equals("Char",Char);
  • 相关阅读:
    Python注释及变量
    MySQL期末测试
    SQL查询第三次训练(重点关照对象)
    MySQL内置函数
    聚类-kmeans
    《达.芬奇密码》丹-布朗
    皮克定理与证明
    常见设计模式的种类与一些原则
    时间序列(二)分解、各部分计算方法
    ADF检验
  • 原文地址:https://www.cnblogs.com/Twittery/p/14971281.html
Copyright © 2011-2022 走看看