Which two code fragments, when inserted independently at line **, enable the code to compile?

Given the following code fragment:
<code>
public static void getInfo() {
//insert code here
List fontCatalog = new ArrayList();
fontCatalog.add(“Algerian”);
fontCatalog.add(“Cambria”);
fontCatalog.add(“Lucida Bright”);
category.put(“firstCategory”,fontCatalog);
List entrySet = new ArrayList(category.entrySet());
Iterator it = entrySet.iterator();
while(it.hasNext()) {
System.out.println(it.next));
}
}
</code>

Which two code fragments, when inserted independently at line **, enable the code to compile?

Given the following code fragment:
<code>
public static void getInfo() {
//insert code here
List fontCatalog = new ArrayList();
fontCatalog.add(“Algerian”);
fontCatalog.add(“Cambria”);
fontCatalog.add(“Lucida Bright”);
category.put(“firstCategory”,fontCatalog);
List entrySet = new ArrayList(category.entrySet());
Iterator it = entrySet.iterator();
while(it.hasNext()) {
System.out.println(it.next));
}
}
</code>

Which two code fragments, when inserted independently at line **, enable the code to compile?

A.
Map<String, List<String>> category = new HashMap<List> ();

B.
Map<String, List<String>> category = new HashMap<<>,List<>>();

C.
Map<String, List<String>> category = new HashMap<> ();

D.
Map<String, List<String>> category = new HashMap <String, ArrayList<String>> ();

E.
Map<String, List<String>> category = new HashMap<String, List<String>> ();

F.
Map<String, List<String>> category = new HashMap<String, List <>> ();

Explanation:
E: Redundant type arguments in new expressions. Use diamond operator instead.



Leave a Reply 0

Your email address will not be published. Required fields are marked *