Question: In this exercise, you will create a couple of helper methods for ArrayLists in a class called ArrayListMethods. Create three static methods: print- This method

In this exercise, you will create a couple of helper methods for ArrayLists in a class called ArrayListMethods.

Create three static methods:

  1. print- This method takes an ArrayList as a parameter, and simply prints each value of the ArrayList on a separate line in the console.
  2. condense- This method takes an ArrayList as a parameter, and condenses the ArrayList into half the amount of values. While traversing, this method will take the existing value at the index and add the index following to the existing value. For example, if we had an ArrayList that consisted of Strings ["0", "1", "2", "3"], the ArrayListMethods.condense(["0", "1", "2", "3"]) would alter the ArrayList to be ["01", "23"].
  3. duplicate- This method takes an ArrayList and duplicates the value of the index at the position index + 1. As a result, ArrayListMethods.duplicate(["01", "23"] would be ["01", "01", "23", "23"].

If done correctly, the methods should work in the ArrayListMethodsTester file.

[ArrayListMethodsTester.java]

import java.util.ArrayList;

public class ArrayListMethodsTester { public static void main(String[] args) { ArrayList stringArray = new ArrayList(); stringArray.add("This"); stringArray.add("is"); stringArray.add("an"); stringArray.add("ArrayList"); stringArray.add("of"); stringArray.add("Strings"); ArrayListMethods.print(stringArray); System.out.println(" ArrayList is condensing:"); ArrayListMethods.condense(stringArray); ArrayListMethods.print(stringArray); System.out.println(" ArrayList is duplicating:"); ArrayListMethods.duplicate(stringArray); ArrayListMethods.print(stringArray); } }

[ArrayListMethods.java]

import java.util.ArrayList; public class ArrayListMethods {

}

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!