Java OCA OCP Practice Question 923

Question

Given the following,

Map<String> names = new HashMap<String>(); 

which of the following are legal?

Choose all that apply.

  • A. Iterator<String> iter = names.iterator();
  • B. for (String s:names)
  • C. while (String s:names)


A, B.

Note

A is the way to get a generic Iterator over a generic Set.

B uses the enhanced for loop to iterate the Set's elements.

C is illegal because there is no such thing as an enhanced while loop.




PreviousNext

Related