How to Create a Sub Array from Another Array in Java?
How to Create a Sub-Array from Another Array? Is There a Method That Takes the Indexes from the First Array Such as: methodName(object Array, Int Start, Int...
How to create a sub-array from another array? Is there a method that takes the indexes from the first array such as:
methodName(object array, int start, int end)
I don't want to go over making loops and making my program suffer.
I keep getting error:
cannot find symbol method copyOfRange(int[],int,int)
This is my code:
import java.util.*;
public class testing
{
public static void main(String [] arg)
{
int[] src = new int[] {1, 2, 3, 4, 5};
int b1[] = Arrays.copyOfRange(src, 0, 2);
}
}
8 Answers
You can use
JDK > 1.5
Arrays.copyOfRange(Object[] src, int from, int to)