Java 之数组的复制,
import java.lang.reflect.Array; import java.util.Arrays; public class Demo { public static void main(String[]arge){ int a[]= new int[]{23,52,21,56,76,89,76,98}; //int newArr[] = Arrays.copyOf(a,3);//复制数组,语法:Arrays.copyOf(数组,新数组的长度) int newArr[] = Arrays.copyOfRange(a,3, 6);//指定复制数组,语法:copyOfRange(数组,索引几,复制几个),索引值要小于其后 for(int tmp:newArr){ System.out.print(tmp); } } }
结果:567689