You must also change the calling code. Since the method now requires an ArrayList<
String>
you should provide an ArrayList<String>. So instead of
you must use an ArrayList<String>:
I have two improvements though.
1) use ArrayList<Integer> instead of ArrayList<String>. You require numbers, not just any String. Make sure to validate the input.
2) program against interfaces. Instead of ArrayList you use List, except possibly for the initialization.
You can now use the following code:
That one "odd" line, Arrays.asList(randomNum, randomNum + 1, randomNum + 2), uses varargs. In this case, it requires Objects, so the ints are autoboxed into Integers. The result is a List<Integer>.
Hmmm, wait a second. Arrays.asList has one drawback - you cannot add to or remove from this List. You can solve this by copying the contents into an ArrayList: