Question: Write Java ( define ) a public static method named getAllOdd, that takes an ArrayList as an argument and returns a new ArrayLIst with all

Write Java (define) a public static method named getAllOdd, that takes an ArrayList as an argument and returns a new ArrayLIst with all of the odd values in the argument ArrayList.
given an ArrayList named myList that contains this list of values: {3,2,7,5,8,6},
getAllOdd(myList) will return an ArrayList that contains this list of values: {3,7,5}
You may wish to write some additional code to test your method.
Helpful Hints:
You will need to instantiate a new ArrayList for your method to return
Use a loop to iterate over the elements of an array
Use an if statement to decide whether or not to include each value from the argument ArrayList in the new ArrayList
Use the modulus operator to determine if a value is odd or even

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!