Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

Coding below was given to be edited

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); } }

import java.util.ArrayList; public class ArrayListMethods { }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions