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 ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Util  RSS feed

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!folks
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.*;
2.
3. class Q33{
4.
5. public static void main(String[] args){
6.
7. <Collection> l = new <Collection>();
8.
9. l.add(null);
10. l.add(null);
11.
12. System.out.println(l.size());
13.
14. }
15.
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:
LinkedList
ArrayList
Vector
------------------
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
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!