nerdexam
Oracle

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.

Generics and Collections

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)
  • A
    7% (4)
  • B
    2% (1)
  • C
    73% (44)
  • D
    15% (9)
  • F
    3% (2)

Explanation

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

Topics

#HashMap#diamond operator#generics#type inference

Community Discussion

No community discussion yet for this question.

Full 1Z0-805 Practice