Arrays.asList(T… a)
初始化一个内部实现的ArrayList,此对象不支持修改,即不支持修改,删除和增加功能。
import org.apache.commons.lang.StringUtils;
List<SysUser> list = userService.list(null);
//List转Array[Object] 不推荐
Object[] objects = list.toArray();
System.out.println("objects----:" + Arrays.toString(objects));
//List转Array[E] 推荐使用 数组长度可设置为list.size()
SysUser[] sysUsers = list.toArray(new SysUser[0]);
System.out.println("sysUsers----:" + Arrays.toString(sysUsers));
//使用流处理方式获得Array
Integer[] integers = list.stream().map(SysUser::getId).toArray(Integer[]::new);
System.out.println("integers----:" + Arrays.toString(integers));
//Arrays.asList(sysUsers) 返回一个受指定数组支持的固定大小的列表.所以不能做 Add Remove 等操作
//结合运用ArrayList的构造方法是目前来说最完美的作法,代码简洁,效率高:
ArrayList<SysUser> sysUsers1 = new ArrayList<>(Arrays.asList(sysUsers));
System.out.println("sysUsers1----:" + sysUsers1.toString());
String join = StringUtils.join(list, ",");
System.out.println("join----:" + join);
//StringUtils中的拼接方法
String join1 = StringUtils.join(integers, ",");
System.out.println("join1----:" + join1);
[
{
"address": "",
"birthday": "2019-07-12",
"createTime": "2019-07-10T14:41:33",
"delFlag": "删除",
"id": 1,
"sex": "女人",
"updateTime": "2019-07-14T19:36:57",
"userName": "王五"
},
{
"address": "北京市",
"birthday": "2014-07-10",
"createTime": "2019-07-10T14:41:33",
"delFlag": "正常",
"id": 2,
"sex": "男人",
"updateTime": "2019-07-13T00:26:35",
"userName": "张三"
},
{
"address": "河南郑州",
"birthday": "2019-07-12",
"createTime": "2019-07-10T14:41:33",
"delFlag": "正常",
"id": 3,
"sex": "男人",
"updateTime": "2019-07-14T19:36:58",
"userName": "张小明"
}
]