逗号拼接字符串转list[通俗易懂]

逗号拼接字符串转list[通俗易懂]将一个用逗号分隔的字符串转为list,代码如下:Stringstr=”aa,aaaa,ddd,ads,sasd”;Typetype=newTypeToken<List<String>>(){}.getType();List<String>list=newGson().fromJson(str,type);个人记录常用代码。…

大家好,又见面了,我是你们的朋友全栈君。

将一个用逗号分隔的字符串转为list,代码如下:
//普通拼接方式
String str="aa,aaaa,ddd,ads,sasd";
Type type = new TypeToken<List<String>>() {}.getType();
List<String> list= new Gson().fromJson(str, type);

//java8流式拼接
//1.
//comRecInfoList是对象list    filter()中是筛选条件
comRecInfoList.stream().filter(rec -> rec.getOrgid().equals(orgId)).collect(Collectors.toList());
//2.
Object[] objects = list.stream().map(OrgInternal::getId).toArray();

orgId = StringUtils.join(objects, ",");


//mybatis中使用
AND r.orgid in
<foreach close=")" collection="list" index="index" item="item" open="(" separator=",">
  #{item}
</foreach>

个人记录常用代码。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/146596.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号