I'm new to Java and hoping for some advice on instantiating List<Integer> arrays within a user defined constructor.
for example:
import java.util.*;
public class Sample {
// variables
private List<Integer> myList = new ArrayList<>();
// constructor
// list of values something like (1,2,3,4,5)
public Sample(List<Integer> listOfValues)
{
{
myListArrays.addAll(Arrays.asList( listOfValues ));
}
}
}
So my constructor call would be:
Sample s = new Sample((1,2,3,4,5));
Is it possible to do something like the above or is there an alternative approach to this type of assignment?