Define the alter_the_list() function which is passed a string of text and a list
ID: 3872308 • Letter: D
Question
Define the alter_the_list() function which is passed a string of text and a list of words as parameters. The function removes any word from the parameter list of words which is a separate word in the string of text. The string of text should be converted to lower case before you do any checking as the elements of the parameter list of words are all in lower case. Note that there is no punctuation in the parameter string of text. Note that each word in the parameter list of word is unique, i.e., it occurs only once. For example, the following code:
Test
Expected
Explanation / Answer
//The function removes any word from the parameter list of words which is a separate word in the string of text.
public static void alter_the_list(String s, ArrayList<String> word_list) {
s=s.toLowerCase();
String str[] = s.split(" ");
ArrayList<String> s1= new ArrayList<String>(Arrays.asList(str));
word_list.remove(s1);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.