• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
  • paul wheaton
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Rob Spoor
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:

Util

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Won't you please? Please won't you be my neighbor? - Fred Rogers. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic