Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Util  RSS feed

Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please answer this question
For what values of the <Collection> in the following code will the program when compiled and run give error. (Select three Correct Answers):
1. import java.util.*;
3. class Q33{
5. public static void main(String[] args){
7. <Collection> l = new <Collection>();
9. l.add(null);
10. l.add(null);
12. System.out.println(l.size());
14. }
16. }
a. HashSet
b. LinkedList
c. Hashtable
d. HashMap
e. TreeMap
f. Vector
g. TreeSet
h. ArrayList
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
add(Object) is a method of the Collection interface so we need things that implement Collection. Maps use the put(Object, Object) to add things. That would leave Sets and Lists. Sets do not allow duplicates so that leaves Lists.
So we need things that implement the List interface:
Co-Moderator of the Programmer Certification Forums
How do they get the deer to cross at the signs? Or to read this tiny ad?
how do I do my own kindle-like thing - without amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!