基于StringUtils实现List和String字符串互转

将以逗号分割的字符串转换成List类型:

String ids= "1,2,32,59,96";
List<Long> idsList = Arrays.asList(ids.split(",")).stream().map(s -> Long.parseLong(s.trim())).collect(Collectors.toList());

基于StringUtils把List转换成String:

ids = StringUtils.join(idsList, ",");
String result = StringUtils.strip(idsList.toString(),"[]");
System.out.println(result);
posted @ 2021-11-24 21:00  楼兰胡杨  阅读(490)  评论(0编辑  收藏  举报