SE251:Session4ShortQuestions
Session 4 Short Answer Questions
1. Under what circumstances would a call to Iterator.next() throw a NoSuchElementException?
2. Is this valid:
List<String> list = new List<String>();
3. Is this valid:
LinkedList<List> list = new LinkedList<List>();
4. What will be the output:
Vector<String> list = new Vector<String>(); list.add("hello"); Iterator<String> i = list.iterator(); System.out.println(i);
5. Is this valid:
Vector<String> list = new Vector<String>(); list.add("hello"); Iterator i = list.iterator(); String str = i.next();
6. What will be the output?
Vector<String> list = new Vector<String>(); list.add("one"); list.add("two"); Iterator<String> i = list.iterator(); System.out.println(i.next());
7. What will be the output?
TreeSet<String> list = new TreeSet<String>(); list.add("Pig"); list.add("Albatross"); list.add("Unicorn"); Iterator i = list.iterator(); System.out.println(i.next());
8. Which of the following lines are valid:
Queue queue = new LinkedList(); List list = new LinkedList();
9. HashMap does not implement Iterable, and neither do its superclasses. Nevertheless it is possible to obtain an iterator for the entries of a HashMap. How?