I want to compare the two following methods :
// We reuse the previously created object copy
public double first(double[] input, double[] copy) {
copy = Arrays.copyOf(input, input.length);
Arrays.sort(copy);
return copy[0];
}
// We create the object copy inside the method
public double second(double[] input) {
double[] copy = Arrays.copyOf(input, input.length);
Arrays.sort(copy);
return copy[1];
}
Will first
be faster than second
?
How does the garbage collector behave ?
What is the impact of coding like first
on larger projects ?
What happens if calling first(input,null)
?