不定时更新Java代码。
StreamUtils
1 | package com.itjing.utils; |
逗号分隔的字符串和List互转
将逗号分隔的字符串转换为List
1 | // 字符型 |
将List转换为逗号分隔的字符串
1 | List<Integer> numList = Lists.newArrayList(1, 2, 3, 4, 5, 6); |
将List对象转换为逗号分隔的字符串
1 | String names = this.list.stream().map(User::getName).collect(Collectors.joining(",")); // a,b,c |
或
1 | StringJoiner sj = new StringJoiner(",", "[", "]"); |