arraycopy方法(实现两个数组之间固定位置的相互转换)

来源:互联网 发布:js字符串include 编辑:程序博客网 时间:2024/06/06 17:33

代码:

import java.util.Arrays;

public class Example7_3 {

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  char a[] = { 'A', 'B', 'C', 'D', 'E', 'F' }, b[] = { '1', '2', '3',
    '4', '5', '6' };
  int c[] = { -1, -2, -3, -4, -5, -6 }, d[] = { 10, 20, 30, 40, 50, 60 };
  System.arraycopy(a, 0, b, 0, a.length - 3);
  System.arraycopy(b, 0, a, 3, b.length - 3);
  System.arraycopy(d, 5, c, 5, 1);
  System.out.println(Arrays.toString(a));
  System.out.println(Arrays.toString(b));
  System.out.println(Arrays.toString(c));
  System.out.println(Arrays.toString(d));
 }

}

答案:


阅读全文
0 0
原创粉丝点击