数组,集合,字符串,bean,map

时间:2023-03-08 21:51:54
数组,集合,字符串,bean,map
    //【字符串】转成【数组】
String[] arr = "1,2,3,4,5,6".split(",");
//【String数组】转成【Long数组】
Long[] LongIds= (Long[]) ConvertUtils.convert(arr, Long.class);
//【数组】 转 【ArrayList】
ArrayList<Long> ids = new ArrayList<Long>(Arrays.asList(LongIds));
//数组转换成集合
List<T> id= Arrays.asList(T[] x);
//集合转数组
Integer[] integers = list.toArray(new Integer[0]);
Map和Bean的相互转换
BeanUtils位于org.apache.commons.beanutils.BeanUtils下面
Map<String, String> map = BeanUtils.describe(person1);  bean 装 map
T bean BeanUtils.populate(bean, map); map 转 bean