【Java】使用 Arrays.copyOf 进行数组复制

import java.util.Arrays;
02  
03 public class ArrayCopy {
04   public static void main(String args[]) {
05     System.out.printf("Before (original)\t%s%n", Arrays.toString(args));
06     String copy[] = Arrays.copyOf(args, 4);
07     System.out.printf("Before (copy)\t\t%s%n", Arrays.toString(copy));
08     copy[0] = "A";
09     copy[1] = "B";
10     copy[2] = "C";
11     copy[3] = "D";
12     System.out.printf("After (original)\t%s%n", Arrays.toString(args));
13     System.out.printf("After (copy)\t\t%s%n", Arrays.toString(copy));
14   }
15 }

你可能感兴趣的:(java)