Posts

What are the differences between a HashMap and a Hashtable in Java?

Image
What are the differences between a  HashMap  and a  Hashtable  in Java? Which is more efficient for non-threaded applications? java collections hashmap hashtable Share Improve this question Follow edited  Aug 1, 2020 at 11:19 Steve Chambers 34.8k 20 20 gold badges 148 148 silver badges 195 195 bronze badges asked  Sep 2, 2008 at 20:12 dmanxiii 50.3k 10 10 gold badges 32 32 silver badges 23 23 bronze badges 38 HashTable is obsolete in Java 1.7 and it is recommended to use ConcurrentMap implementation   –  MissFiona   Apr 9, 2017 at 22:10 9 @MissFiona No,  ConcurrentMap  is  not necessary here, as the Question says “non-threaded applications” meaning threading/concurrency is not an issue. –  Basil Bourque   Dec 29, 2019 at 1:11   4 @BasilBourque, Yes, but I believe what MissFiona meant by that was something akin to  " HashTable  has traditionally been only chosen because of its partial threading protectio...

Avoiding NullPointerException in Java

I use  x != null  to avoid  NullPointerException . Is there an alternative? if (x != null ) { // ... } java nullpointerexception null Share Follow edited  Jul 10 at 23:18 community wiki 36 revs, 29 users 10% Goran Martinic 138 @Shervin Encouraging nulls makes the code less understandable and less reliable.   –  Tom Hawtin - tackline   Aug 2, 2010 at 9:17 80 Not using null is superior to most other suggestions here. Throw exceptions, don't return or allow nulls. BTW - 'assert' keyword is useless, because it's disabled by default. Use an always-enabled failure mechanism   –  ianpojman   Jun 8, 2012 at 19:40   You can create class that will check for null values or null object. That will help you improving reuse-ability..  stackoverflow.com/a/16833309/1490962 –  Bhushankumar Lilapara   May 30, 2013 at 10:15 use  Lombok , you got  @NotNull   –  wener Oct 9, 2013 at 18:21   1 Isn't there are ...