Question: IN JAVA * Removes all o elements from an ArrayList import java.util.ArrayList; public class RemoveZeroes { public static void main(String[] args) { ArrayList a =

IN JAVA

IN JAVA * Removes all o elements from an ArrayList import java.util.ArrayList;

* Removes all o elements from an ArrayList import java.util.ArrayList; public class RemoveZeroes { public static void main(String[] args) { ArrayList a = new ArrayList(); // Add some integers to the array list a.add(14); a. add(); a.add(19); a. add(3); a.add(15); a.add(0); a.add(18); a.add(0); a.add(44); a.add(0); a.add(51); a. add(78); // You can also create an Integer wrapper explicitly and add to the array list a.add(new Integer(83)); // Print the array list - Note the use of the size() method and the get() method System.out.println("Before removing the o elements:"); for (int i = 0; i ano Zeros = removeZeros(a); // Print ArrayList a again to see new elements. System.out.println("After removing the elements:"); for (int i = 0; i removeZeros(ArrayList p) { // The best way: Create a new empty integer array list and // only copy the non-zero numbers of parameter array list p into it. // Use a for loop --Start below here. To do: approximate lines of code = 5 1/- // Return the reference to the newly created array list ---End here. Please do not remove this comment. Reminder: no changes outside the todo regions. }

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 Databases Questions!