Question: Hold the broccoli, again! Create a new Map with entries, remove one of its entries, then check if the value is still in the Map.
Hold the broccoli, again!
Create a new Map with entries, remove one of its entries, then check if the value is still in the Map.
Steps:
Initialize a new TreeMap of type String called vegetables.
Add the following key:value pairs to the Map:c : "carrot"b : "broccoli"s : "spinach"t : "tomato"a : "asparagus"
Print the Map to the console using System.out.printlnBefore: vegetables;
Remove "broccoli" from the Map by using its key.
Print the Map to the console again using System.out.printlnAfter: vegetables;
Declare a boolean variable named containsBroccoli and set it equal to a method that will check if "broccoli" is still in the Map vegetables.
Execute your code.
Does the Map contain b : "broccoli"? The result should be false.
import java.io;
import java.util.;
import java.text.;
import java.math.;
import java.util.regex.;
public class TreeMapQuestion
public static void mainString args
WRITE YOUR CODE HERE
DO NOT CHANGE THE CODE BELOW THIS LINE
System.out.println;
System.out.printlnDoes the Map contain 'broccoli'? containsBroccoli;
end of main
EXPECTED SDOUT
Before:aasparagus,bbroccoli,ccarrot,sspinach,ttomato
After:aasparagus,ccarrot,sspinach,ttomato
DoestheMapcontainbroccolifalse
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
