File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Map Vs Dictionary Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Map Vs Dictionary" Watch "Map Vs Dictionary" New topic
Author

Map Vs Dictionary

sumit anand kumar
Ranch Hand

Joined: Apr 28, 2010
Posts: 83
I know Dictionary has been unoffficially deprecated. But comparing Map & DIctionary, I can't find any differences.
Is there a basic design difference i missed?
Also since now its unofficially deprecated, doesn't it means we should not be encouraged to use HashTable and use ConcurrentHashMap instead.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

sumit anand kumar wrote:I know Dictionary has been unoffficially deprecated. But comparing Map & DIctionary, I can't find any differences.
Is there a basic design difference i missed?


Dictionary is an abstract class. Map is an interface.

Dictionary uses classes and methods that predate the Collections Framework. Map uses classes and methods that were created to be part of the Collections Framework from the ground up.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36478
    
  16
There is no such thing as unofficially deprecated. But many people regard Dictionary as legacy code, and the API describes it as obsolete.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

I think, Map is a new term of Dictionary ADT.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36478
    
  16
Seetharaman Venkatasamy wrote:I think, Map is a new term of Dictionary ADT.
Afraid it isn’t. The two are similar, however.
Walter Gabrielsen Iii
Ranch Hand

Joined: Apr 09, 2011
Posts: 158
I read somewhere that because Dictionary is an abstract class instead of an interface like Map, and because Java classes can only have 1 superclass, all of Dictionary's subclasses are forever trapped under the Dictionary inheritance tree and can't be moved to fill other rolls in other inheritance trees.

Dictionary is more like java.util.AbstractMap than the Map interface.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36478
    
  16
Walter Gabrielsen Iii wrote: . . . because Java classes can only have 1 superclass, all of Dictionary's subclasses are forever trapped . . .
That is correct. Also, by implementing an interface, you can make a class appear to extend two things (or more).

Both of those are advantages to implementing rather than extending something.
 
jQuery in Action, 2nd edition
 
subject: Map Vs Dictionary
 
Similar Threads
Generics & explicit casting
WA #1.....word association
Map & dictionary
Translation and language comparison
Hashtable and other collection classes using hashing