Please answer the question posted and give full explanation of the answer. Please past the successful program run as well. Create a Java project with the following code. Please remember to type in this code rather than copy-and-pasting; Word loves to mangle source code. import java.util.*; import java.io.*; public class ArrayListTest { public static void main(String[] args) { String myString = "To be, or not to be,\r\n" + "that is the question. Whether 'tis\r\n" + "nobler in the mind to suffer\r\n" + "the slings and arrows of outrageous fortune,\r\n" + "Or to take Arms against a Sea of Troubles\r\n" + "And by opposing end them.\r\n"; // build the list of stop words ArrayList stopWords = new ArrayList(); stopWords.add("a"); stopWords.add("be"); stopWords.add("by"); stopWords.add("how"); stopWords.add("in"); stopWords.add("is"); stopWords.add("it"); stopWords.add("of"); stopWords.add("on"); stopWords.add("or"); stopWords.add("that"); stopWords.add("the"); stopWords.add("this"); stopWords.add("to"); stopWords.add("why"); // process the file, printing all but stop words Scanner input = new Scanner(myString); while (input.hasNext()) { String next = input.next(); if (!stopWords.contains(next.toLowerCase())) { System.out.print(next + " "); } } } } Once the program works as expected, answer the following questions: 2.1. The ArrayList is declared using ArrayList. What does mean in this context? a. The ArrayList is stored inside a single String String is the template type for the ArrayList The ArrayList is cast to String for purposes of .ToString 2.2. Can you add items to an ArrayList after it has been declared? Yes / No 2.3. What method do we use to add items to an ArrayList? 2.4. Which method is used in the if statement to check if a word should or should not be printed? 2.5. What is the meaning of the exclamation point (!) in the Boolean expression of the if condition?
Please answer the question posted and give full explanation of the answer. Please past the successful program run as well.
Create a Java project with the following code. Please remember to type in this code rather than copy-and-pasting; Word loves to mangle source code.
import java.util.*;
import java.io.*;
public class ArrayListTest {
public static void main(String[] args) {
String myString = "To be, or not to be,\r\n" +
"that is the question. Whether 'tis\r\n" +
"nobler in the mind to suffer\r\n" +
"the slings and arrows of outrageous fortune,\r\n" +
"Or to take Arms against a Sea of Troubles\r\n" +
"And by opposing end them.\r\n";
// build the list of stop words
ArrayList<String> stopWords = new ArrayList<String>();
stopWords.add("a");
stopWords.add("be");
stopWords.add("by");
stopWords.add("how");
stopWords.add("in");
stopWords.add("is");
stopWords.add("it");
stopWords.add("of");
stopWords.add("on");
stopWords.add("or");
stopWords.add("that");
stopWords.add("the");
stopWords.add("this");
stopWords.add("to");
stopWords.add("why");
// process the file, printing all but stop words
Scanner input = new Scanner(myString);
while (input.hasNext()) {
String next = input.next();
if (!stopWords.contains(next.toLowerCase())) {
System.out.print(next + " ");
}
}
}
}
Once the program works as expected, answer the following questions:
2.1. The ArrayList is declared using ArrayList<String>. What does <String> mean in this context?
a. The ArrayList is stored inside a single String
- String is the template type for the ArrayList
- The ArrayList is cast to String for purposes of .ToString
2.2. Can you add items to an ArrayList after it has been declared? Yes / No
2.3. What method do we use to add items to an ArrayList?
2.4. Which method is used in the if statement to check if a word should or should not be printed?
2.5. What is the meaning of the exclamation point (!) in the Boolean expression of the if condition?
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 3 images