Ask Question
10 July, 17:21

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.

+4
Answers (1)
  1. 10 July, 17:51
    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?
Get 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 & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers