Java: most efficient way to defensively copy an int[]?
- by Jason S
I have an interface DataSeries with a method
int[] getRawData();
For various reasons (primarily because I'm using this with MATLAB, and MATLAB handles int[] well) I need to return an array rather than a List.
I don't want my implementing classes to return the int[] array because it is mutable. What is the most efficient way to copy an int[] array (sizes in the 1000-1000000 length range) ? Is it clone()?