1Z0-805 · Question #69
Given the following code fragment: public static void getInfo() { //insert code here List fontCatalog = new ArrayList(); fontCatalog.add("Algerian"); fontCatalog.add("Cambria")…
The correct answer is C. Map<String, List<String>> category = new HashMap<> (); E. Map<String, List<String>> category = new HashMap<String, List<String>> (). E: Redundant type arguments in new expressions. Use diamond operator instead.
Question
Given the following code fragment:
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)); } } Which two code fragments, when inserted independently at line **, enable the code to compile?
Options
- AMap<String, List<String>> category = new HashMap<List> ();
- BMap<String, List<String>> category = new HashMap<<>,List<>>();
- CMap<String, List<String>> category = new HashMap<> ();
- DMap<String, List<String>> category = new HashMap <String, ArrayList<String>> ();
- EMap<String, List<String>> category = new HashMap<String, List<String>> ();
- FMap<String, List<String>> category = new HashMap<String, List <>> ();
How the community answered
(60 responses)- A7% (4)
- B2% (1)
- C73% (44)
- D15% (9)
- F3% (2)
Explanation
E: Redundant type arguments in new expressions. Use diamond operator instead.
Topics
Community Discussion
No community discussion yet for this question.