Given:
2. import java.util.*; 3. public class Main { 4. public static void main(String[] args) { 5. Set<Integer> s = new TreeSet<Integer>(); 6. s.add(23); s.add(42); s.add(new Integer(5)); 7. Iterator i = s.iterator(); 8. // while(System.out.print(i.next())) { } 9. // for(Integer i2: i) System.out.print(i2); 10. // for(Integer i3: s) System.out.print(i3); 11. // while(i.hasNext()) System.out.print(i.get()); 12. // while(i.hasNext()) System.out.print(i.next()); 13. } } /*from w w w . ja va2 s . co m*/
If lines 8-12 are uncommented, independently, which are true? (Choose all that apply.)
C, E, and G are correct.
Line 10 is a legal for-each loop.
Line 12 uses legal syntax to iterate over the Set.
Because this is a TreeSet, the output will be sorted.