Ask Question
23 September, 19:37

Write a method called listSearch () that takes in a target string and a list of other strings. This method returns a (possibly shorter) list containing all of the strings from the original list that themselves contain the target string you are searching for. Check for the target string as a case-sensitive substring of every member of the list. You can either modify the provided list or create a new one.

+3
Answers (1)
  1. 23 September, 20:59
    0
    public static List listSearch (String searchFor, List list) {

    List foundList = new ArrayList ();

    for (String s:list) {

    if (s. contains (searchFor)) {

    foundList. add (s);

    }

    }

    return foundList;

    }

    Explanation:

    Create a method named listSearch that takes two parameters, a String named searchFor and a String list named list

    Inside the method, initialize a new String list named foundList, this will be used to hold the strings that contains the target string. Create a for loop that iterates through the list. Check if a string in the list contains the searchFor using the contains method. If it does, add the string to the foundList. When the loop is done, return the foundList.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a method called listSearch () that takes in a target string and a list of other strings. This method returns a (possibly shorter) ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers