Java_数组操作_提取数组的一部分生成另一个数组

package test;

import java.util.Arrays;

public class test {

	public static void main(String[] args) {
		int a[] = new int[] { 10, 5, 3, 2, 6, 8, 7, 9, 1, 4 };
		int b[] = Arrays.copyOfRange(a, 2, 6);// 截取索引2(包括)到索引6(不包括)的元素
		System.out.println(Arrays.toString(b));
	}
}

输出:

[3, 2, 6, 8]


版权声明:本文为u012552052原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。