类型之前互转

1.List<String> list = Arrays.asList(str.split(","));

2.List<String> userList= JSONArray.parseArray(user,String.class);

3.List<User> userList=JSONArray.parseArray(user,User.class);

 

1.jsonobject转对象:JSONObject json = (JSONObject) JSONObject.toJSON(obj);

                                  PolicyBean vo = JSONObject.toJavaObject(json, PolicyBean.class);

2.List<ConfigEntityVO> attrLists = JSON.parseArray(vo.getAttrs(), ConfigEntityVO.class);

3.JSONObject attrLists = JSON.parseObject(vo.getAttr(), JSONObject.class) ;

4.map转对象 :

Map<String, Object> configUserInfo = null;
configUserInfo = (Map<String, Object>) object.get("userinfo");
userinfo = JSONObject.parseObject(JSONObject.toJSONString(configUserInfo), UserLoginDTO.class);

5.list数组转Sting用逗号分隔

String str = String.join(",", list);‘

String str = StringUtils.json(list.toArray(), ","); 

6.java中string拆分数组「字符串数组」,转Integer数组,再转List<Integer>集合

String str = "1,2,3"
// 从策略中获取通知方式; 转成Integer数组
Integer[] arr= Convert.toIntArray(str.split(","));
// 将Integer数组转成List<Integer>
List<Integer> categoryList = Arrays.asList(arr);

/**
* 输出结果:
* [1,2,3]
*/
————————————————
版权声明:本文为CSDN博主「阿飞狂说」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_46239275/article/details/123419769

posted @ 2023-03-08 17:51  JLCUI  阅读(10)  评论(0编辑  收藏  举报