ArrayCopy方法int数组、String数组使用实例
来源:互联网 发布:美工刀片什么牌子好 编辑:程序博客网 时间:2024/06/05 18:14
1
package com.szsm.swing.other;import java.lang.reflect.Array;public class Answer_1606 {public static void main(String[] args) {Test test = new Test();test.is = (int[]) addArrayLength(test.is, 10);test.ss = (String[]) addArrayLength(test.ss, 10);test.print();}public static Object addArrayLength(Object array, int newLength) {Object newArray = null;Class componentType = array.getClass().getComponentType();newArray = Array.newInstance(componentType, newLength);System.arraycopy(array, 0, newArray, 0, Array.getLength(array));return newArray;}}class Test {public int[] is = { 1, 2, 3 };public String[] ss = { "A", "B", "C" };public void print() {for (int index = 0; index < is.length; index++) {System.out.println("is[" + index + "]=" + is[index]);}System.out.println();for (int index = 0; index < ss.length; index++) {System.out.println("ss[" + index + "]=" + ss[index]);}System.out.println();}}2
is[0]=1is[1]=2is[2]=3is[3]=0is[4]=0is[5]=0is[6]=0is[7]=0is[8]=0is[9]=0ss[0]=Ass[1]=Bss[2]=Css[3]=nullss[4]=nullss[5]=nullss[6]=nullss[7]=nullss[8]=nullss[9]=null是否调用2是否调用is[0]=1is[1]=2is[2]=3is[3]=0is[4]=0is[5]=0is[6]=0is[7]=0is[8]=0is[9]=0ss[0]=Ass[1]=Bss[2]=Css[3]=nullss[4]=nullss[5]=nullss[6]=nullss[7]=nullss[8]=nullss[9]=null
- ArrayCopy方法int数组、String数组使用实例
- string[]数组转为int[]数组方法
- System提供了一个静态方法arraycopy(),我们可以使用它来实现数组之间的复制。 其函数原型是: public static void arraycopy(Object src, int
- Java数组拷贝方法arraycopy()
- 《arraycopy()方法复制两个数组》
- arraycopy方法和二维数组
- java 使用arraycopy拷贝数组
- System.arraycopy使用复制数组
- byte[] 数组越界,System.arraycopy()方法
- JavaSE_30th_数组——arraycopy()方法
- Java使用System.arraycopy复制数组
- java使用System.arraycopy对数组扩容
- java数组复制(arraycopy)
- [Java] arraycopy 数组复制
- 二维数组和arraycopy
- 数组合并System.arraycopy
- 数组System.arraycopy
- arraycopy数组的拷贝
- Swing中常用的复杂继承关系测试实例
- Swing中流式布局实例
- powerdesigner转换成word文档报告的定制
- Swing之Gridbaglayout使用以及通过反射技术验证属性表框实例
- ubuntu 常见错误--Could not get lock /var/lib/dpkg/lock
- ArrayCopy方法int数组、String数组使用实例
- 用栈解决四则运算问题
- 489 - Hangman Judge(string的find函数)
- POJ 1611 并查集详解+基础应用
- Java中的泛型
- 基于LVS负载均衡的高性能Web站点设计与实现
- android_切换屏处理_获取所有APP包名_安装apk
- 浅谈析构函数的调用顺序
- 实现一个线程安全的队列,并模拟进行生产者-消费者问题