//package com.nowjava;
public class Main {/*n o w j a v a . c o m 提供*/
public static void main(String[] argv) throws Exception {
Object[] data = new String[] { "1", "abc", "level", null,
"nowjava.com", "asdf 123" };
int startIndex = 2;
int endIndex = 2;
System.out.println(java.util.Arrays.toString(subArray(data,
startIndex, endIndex)));
}
/**
* Get a part on an array
* @param data The array to get the sub array from
* @param startIndex The first index of the subarray
* @param endIndex The first index not in the subarray (last index +1)
* @return an array with the elements from data in the fields startIndex to endIndex-1
*/
public static Object[] subArray(Object[] data, int startIndex,
int endIndex) {
Object[] output = new Object[endIndex - startIndex];
for (int i = startIndex; i < endIndex; i++) {
output[i - startIndex] = data[i];
}/*来自 时 代 J a v a 公 众 号 - N o w J a v a . c o m*/
return output;
}
/**
* Get a part on an array
* @param data The array to get the sub array from
* @param startIndex The first index of the subarray
* @param endIndex The first index not in the subarray (last index +1)
* @return an array with the elements from data in the fields startIndex to endIndex-1
*/
public static boolean[] subArray(boolean[] data, int startIndex,
int endIndex) {
boolean[] output = new boolean[endIndex - startIndex];
for (int i = startIndex; i < endIndex; i++) {
output[i - startIndex] = data[i];
}
return output;
}
/**
* Get a part on an array
* @param data The array to get the sub array from
* @param startIndex The first index of the subarray
* @param endIndex The first index not in the subarray (last index +1)
/**代码未完, 请加载全部代码(NowJava.com).**/
本文系作者在时代Java发表,未经许可,不得转载。如有侵权,请联系nowjava@qq.com删除。