提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
按偏移量和长度划分的切片数组
//package com.nowjava;/** 来 自 N o w J a v a . c o m**/ public class Main { public static void main(String[] argv) throws Exception { String[] strings = new String[] { "1", "abc", "level", null, "nowjava.com", "asdf 123" }; int begin = 2; int length = 2; System.out.println(java.util.Arrays.toString(slice(strings, begin, length))); } public static String[] slice(String[] strings, int begin, int length) { String[] result = new String[length]; for (int i = 0; i < length; i++) { result[i] = strings[begin + i]; } return result; } /** * 时代Java - nowjava.com 提 供 **/ public static Object[] slice(Object[] objects, int begin, int length) { Object[] result = new Object[length]; for (int i = 0; i < length; i++) { result[i] = objects[begin + i]; } return result; } public static String toString(Object[] array) { StringBuffer sb = new StringBuffer(); sb.append("[");