转义字符转换成不转义字符
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>${commons.text.version}</version>
</dependency>
String output = StringEscapeUtils.escapeJava(input);
列表转换成树形
public static <T, I> List<T> setChildren(Collection<T> coll, I topId, Function<T, I> idGetter, Function<T, I> parentIdGetter, BiConsumer<T, List<T>> childSetter) {
List<T> tree = new ArrayList<>();
if (Objects.isNull(coll) || coll.isEmpty()) {
return tree;
}
Map<I, List<T>> collGroupByParentId = coll.stream().collect(Collectors.groupingBy(parentIdGetter, Collectors.toList()));
for (T item : coll) {
I itemId = idGetter.apply(item);
List<T> itemChildren = collGroupByParentId.getOrDefault(itemId, new ArrayList<>());
childSetter.accept(item, itemChildren);
}
tree.addAll(collGroupByParentId.getOrDefault(topId, new ArrayList<>()));
return tree;
}