源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

java 重定义数组的实现方法(与VB的ReDim相像)

  • 时间:2021-11-02 11:05 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:java 重定义数组的实现方法(与VB的ReDim相像)
[u]复制代码[/u] 代码如下:
//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; }
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部