Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

urgent questions about collection

 
Han Shu
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I met two problem with collection when doing Mock Exam. Please help!
1.You need to store elements in a collection that guarantees that no duplicates are stored and all elements can be accessed in natural order. Which interface provide that capability?
A.Java.util.Map
B.Java.util.Set
C.Java.util.List
D.Java.util.SortedSet
E.Java.util.SortedMap
F.Java.util.Collection
I wonder the answer is D or E or both.
2.Which statement is true for the class java.util.Hashset?
A. THe elements in the collection are ordered.
B. The collection is guaranteed to be immutaible.
C. The elements in the collection are guaranteed to be unique.
D. The elements in the collection are accessed using a unique key.
E The elements in the collection are guranteed to be synchronized.
Is the answer should be C and D?
 
Ragu Sivaraman
Ranch Hand
Posts: 464
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
han,
I believe
For 1: Ans D
E requires no duplicate keys , but not elements i think
For 2: It clearly C
Becoz, HashSet does not implement Map interface so there are no
key/value issues
Thankx
 
Han Shu
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Ragu!
However, I am still confused by Hashset, Hashtable, Hashmap, which one gurantee to be synchronized, and which on not?
 
Ragu Sivaraman
Ranch Hand
Posts: 464
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Han Shu:
Thank you Ragu!
However, I am still confused by Hashset, Hashtable, Hashmap, which one gurantee to be synchronized, and which on not?


Vector and HashTable are the ones i know which is threa-safe or synchronized

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic