java----js常用的api

java----js常用的api

  • 时间函数
    • 获取当前时间: DateUtil.today()
    • 时间偏移
    • 字符换时间格式化
  • map.computeIfAbsent添加list

时间函数

获取当前时间: DateUtil.today()

String today=DateUtil.today()

String today = “2024-02-01”;

时间偏移

往前退役30天

DateUtil.offsetDay(DateUtil.parse(DateUtil.today()), -30)

字符换时间格式化

DateTime parse = DateUtil.parse(DateUtil.today());
String  today =DateUtil.formatDate(parse)

map.computeIfAbsent添加list

postIdMap.computeIfAbsent(dingDaykey.getPostId(), k -> new LinkedList<>()).add(dingDaykey);

优化前

DayEntity dayEntity = lkeyMap.get(line);
if (dayEntity == null) {
    dayEntity = new DayEntity();
}
dayEntity.setName(line);

优化后

DayEntity dayEntity = lkeyMap.computeIfAbsent(line, DayEntity::new);

优化前

            List<DataListMxfEntity> data = dayEntity.getData();
            if (data == null) {
                data = new ArrayList<>();
            }

优化后

List<DataListMxfEntity> data = Optional.ofNullable(dayEntity.getData()).orElseGet(ArrayList::new);

优化前

            LinkedList<DingDaykey> dingDaykeys1 = postIdMap.get(postId);
            if (dingDaykeys1 != null) {
                gwDingRounddotMap.computeIfAbsent(onlyId, k -> new LinkedList<>()).addAll(dingDaykeys1);
            }

优化后

gwDingRounddotMap.computeIfAbsent(onlyId, k -> dingDaykeys1 != null ? new LinkedList<>(dingDaykeys1) : new LinkedList<>());

你可能感兴趣的:(java,开发语言)