1.合并数组
//数组合并
public String[] mergeArr(String[] str1,String[] str2){
int str1Length = str1.length;
int str2Length = str2.length;
//数组扩容 合并两个数组
str1 = Arrays.copyOf(str1, str1Length+str2Length);
System.arraycopy(str2, 0, str1, str1Length,str2Length );
return str1;
}
2.map 对象转为对象
//将map对象转换对象
public static Object mapToObject(Map<String, Object> map, Class<?> beanClass) throws Exception {
if (map == null) {
return null;
}
Object obj = beanClass.newInstance();
Field[] fields = obj.getClass().getDeclaredFields();
for (Field field : fields) {
int mod = field.getModifiers();
if(Modifier.isStatic(mod) || Modifier.isFinal(mod)){
continue;
}
field.setAccessible(true);
field.set(obj, map.get(field.getName()));
}
return obj;
}
3.JOSN转对象
import com.alibaba.fastjson.JSON;
public Object map2Object(Map map,Class<?> beanClass){
JSONObject jsonObject = new JSONObject(map);
Object t = JSONObject.parseObject(String.valueOf(jsonObject),beanClass);
return t;
}