Question: import java.util.ArrayList; public class ArrayListUtil { /** Finds the positions of all strings equal to a given string in an array list of strings. @param

import java.util.ArrayList;

public class ArrayListUtil { /** Finds the positions of all strings equal to a given string in an array list of strings. @param words an array list of strings @param searchedWord the word to search for @return an array list of all matching positions */ public static ArrayList<. . .> findAll(. . . words, . . . searchedWord) { . . . } }

Use the following file:

Tester.java

import java.util.ArrayList; public class Tester { public static void main(String[] args) { ArrayList words = new ArrayList(); words.add("how"); words.add("much"); words.add("wood"); words.add("would"); words.add("a"); words.add("wood"); words.add("chuck"); words.add("chuck"); words.add("if"); words.add("a"); words.add("wood"); words.add("chuck"); words.add("could"); words.add("chuck"); words.add("wood"); System.out.println(ArrayListUtil.findAll(words, "wood")); System.out.println("Expected: [2, 5, 10, 14]"); System.out.println(ArrayListUtil.findAll(words, "a")); System.out.println("Expected: [4, 9]"); System.out.println(ArrayListUtil.findAll(words, "the")); System.out.println("Expected: []"); } } 

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!