Menu

Exercise Create Couple Helper Methods Arraylists Class Called Arraylistmethods Create Thre Q43877645

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

Create three static methods:

  1. print- This method takes an ArrayList<String> as aparameter, and simply prints each value of the ArrayList on aseparate line in the console.
  2. condense- This method takes an ArrayList<String> as aparameter, and condenses the ArrayList into half the amount ofvalues. While traversing, this method will take the existing valueat the index and add the index following to the existing value. Forexample, 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<String> andduplicates the value of the index at the position index + 1. As aresult, ArrayListMethods.duplicate([“01”, “23”] would be [“01″,”01”, “23”, “23”].

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

[ArrayListMethodsTester.java]

import java.util.ArrayList;

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

[ArrayListMethods.java]

import java.util.ArrayList;
public class ArrayListMethods
{
  
  

}

Expert Answer


Answer to In this exercise, you will create a couple of helper methods for ArrayLists in a class called ArrayListMethods. Create t…

OR