Java高级开发技巧记录

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//对象拷贝
BeanUtils.copyProperties(object, object)

//集合工具
CollectionUtils.isEmpty(list)
List<Long> ids = items.stream().map(p -> p.getId()).collect(Collectors.toList());
list.stream()
.filter(p -> TradeStatus.ONLINE.name().equalsIgnoreCase(p.getTradeStatus()))
.forEach(p -> {

});

//字符串工具
Strings.nullToEmpty(string)

//A|B|C|D|E
List<String> head = Arrays.asList("A", "B", "C", "D", "E");
String rowStr = String.join(separator, head);

//对象工具
Objects.equals(object, object)
Objects.isNull(object)
Objects.nonNull(object)

//日期工具
Date now = DateUtils.truncate(dateTimeHelper.selectDateTime(), Calendar.DAY_OF_MONTH);
String begin = DateFormatUtils.format(DateUtils.addDays(now, -req.getLatestDays()), "yyyyMMdd");
String end = DateFormatUtils.format(DateUtils.addDays(now, -1), "yyyyMMdd");

Date date = "20200101";
DateFormatUtils.format(DateUtils.addDays(date, -1), "yyyyMMdd");

//BigDecimal运算
new BigDecimal(100).divide(new BigDecimal(10000))

//大写
WordUtils.capitalize(profile)

//map遍历
map.entrySet().forEach(entry -> {

});

//线程安全
List<T> list = Collections.synchronizedList(new LinkedList<>());

//AtomicInteger
AtomicInteger count = new AtomicInteger(0);
count.incrementAndGet()
count.intValue()
count.addAndGet(5)

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2020 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :