相当于PHP中的PHP'array_splice'

时间:2011-12-05 07:25:16

标签: java php

如何在java

中实现array_splice()
$input = array("red", "green", "blue", "yellow");
array_splice($input, 2);
// $input is now array("red", "green")

http://php.net/array_splice

2 个答案:

答案 0 :(得分:5)

Java等价物是List.subList(int, int)

答案 1 :(得分:2)

您可以使用Arrays.copyOfRange(sourceArray, start, end);

String[] anArray = new String[] { "red", "green", "blue", "yellow" };
String[] subset = Arrays.copyOfRange(anArray, 0, 2);