addTwo
n this problem, you're practicing how to instantiate a list in java as well as how to use the add method.
Complete the method addTwo
which adds the numbers -1 and 5 at the end of the list in their respective order.
For this problem, is there a return? Look at the method header. Remember the return type comes before the name of the method.
Never return data if a method is void. Note that calling the return keyword exits execution from that method which is ok. But you cannot return data. The statements return;, and return 1; are not the same. When a method is void, you can always end the method early with the return keyword.
Is there a parameter? This is the comma-separated list of variables in the parenthesis of the method name.
The parameter, the list passed into the method, will be the list you should be using.
Syntax:
ArrayList<DataType> name = new ArrayList<DataType>();
//Call add on the list object
name.add(element);
name.add(anotherElement);
The following are methods of a list that can be used to manipulate the contained data.