java 重定义数组的实现方法(与VB的ReDim相像)
时间:2022-08-09 23:09:25
//param objArr the expanded object of Array.
//param newLength the length of the new Array
public static Object getNewArr(Object objArr, int newLength) {
if (!objArr.getClass().isArray()) {//判断类型
return null;
}
// get the array's componentType
Class componentType = objArr.getClass().getComponentType();//获得类型
//get a newInstance of a Array object Object newArray = Array.newInstance(componentType, newLength);//新建数组对象
//copy the array
System.arraycopy(objArr, 0, newArray, 0, Array.getLength(objArr));//把原数组数据copy到新建数组中,其中newLength要大于元objArr的length,否则此句报错
return newArray;
}
标签:重定义,数组
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Proxy实现AOP切面编程案例
2023-07-23 06:44:52
![](https://img.aspxhome.com/file/2023/6/61086_0s.jpg)
Android封装实现短信验证码的获取倒计时
2023-06-28 22:57:23
![](https://img.aspxhome.com/file/2023/9/82399_0s.gif)
Hibernate一级缓存和二级缓存详解
2023-11-16 11:58:11
Flutter倒计时/计时器的实现代码
2023-07-01 03:50:50
![](https://img.aspxhome.com/file/2023/5/103895_0s.jpg)
SpringBoot项目集成Flyway进行数据库版本控制的详细教程
2023-11-24 05:20:33
![](https://img.aspxhome.com/file/2023/0/59390_0s.png)
Java经典面试题最全汇总208道(四)
2023-11-08 23:59:26
![](https://img.aspxhome.com/file/2023/5/59065_0s.png)
java实战之飞机大战小游戏(源码加注释)
2021-08-01 17:46:08
![](https://img.aspxhome.com/file/2023/5/63485_0s.png)
ElasticSearch查询文档基本操作实例
2023-11-24 14:20:02
Java实现红黑树(平衡二叉树)的详细过程
2021-08-08 15:03:12
![](https://img.aspxhome.com/file/2023/3/64493_0s.png)
java实现的RSA加密算法详解
2022-11-19 06:14:44
美化java代码,从合理注释开始
2022-01-18 16:32:47
SpringBoot如何访问html和js等静态资源配置
2023-08-17 08:07:43
![](https://img.aspxhome.com/file/2023/7/63787_0s.png)
Java Swing实现窗体添加背景图片的2种方法详解
2021-10-26 19:01:18
![](https://img.aspxhome.com/file/2023/1/62231_0s.jpg)
java IO流 之 输出流 OutputString()的使用
2023-08-11 23:16:30
详解Spark Sql在UDF中如何引用外部数据
2021-08-17 14:51:17
![](https://img.aspxhome.com/file/2023/4/64124_0s.jpg)
java 汉诺塔Hanoi递归、非递归(仿系统递归)和非递归规律 实现代码
2023-09-13 11:29:31
Java中JDBC连接数据库详解
2023-08-10 16:57:18
![](https://img.aspxhome.com/file/2023/2/58162_0s.png)
使用springboot aop来实现读写分离和事物配置
2022-10-29 11:43:07
![](https://img.aspxhome.com/file/2023/6/69086_0s.jpg)
C#设置Word文档背景的三种方法(纯色/渐变/图片背景)
2022-07-08 01:33:09
![](https://img.aspxhome.com/file/2023/0/67560_0s.jpg)
Java中logback 自动刷新不生效的问题解决
2022-09-07 21:26:04
![](https://img.aspxhome.com/file/2023/8/68558_0s.png)