如何在java
中实现array_splice()
$input = array("red", "green", "blue", "yellow");
array_splice($input, 2);
// $input is now array("red", "green")
答案 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);