• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

hash map.hash table....

 
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HashMap is unsynchronized and Hashtable is synchronized.Vector is synchronized whereas arraylist is not.

How is this justified??
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is there to justify? The synchronized one's are suitable for multi-threaded access and the other ones are not.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hashtable and Vector are legacy collection classes - they are old collection classes that have existed since Java 1.0 (or maybe even earlier).

In Java 1.2 (long ago), new collection classes were added such as HashMap and ArrayList, which more or less replace the old classes. When Sun was developing Java 1.2, they realized that most people don't need synchronization (in most programs, collections are not accessed by multiple threads at the same time), so they left the new collection classes without synchronization. Note that synchronization adds some runtime overhead, so the unsynchronized collections perform better than the synchronized ones.

You should always use the new collection classes. If you need synchronization, you can use utility methods in class Collections to add synchronization wrappers to your collections (for example Collections.synchronizedList(...) etc.), or you can look at the specialized collection classes in package java.util.concurrent.
 
My cellmate was this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic