25条回答 默认 最新
hurriedly% 2008-09-02 23:02关注There are several differences between
HashMapandHashtablein Java:Hashtableis synchronized, whereasHashMapis not. This makesHashMapbetter for non-threaded applications, as unsynchronized Objects typically perform better than synchronized ones.Hashtabledoes not allownullkeys or values.HashMapallows onenullkey and any number ofnullvalues.One of HashMap's subclasses is
LinkedHashMap, so in the event that you'd want predictable iteration order (which is insertion order by default), you could easily swap out theHashMapfor aLinkedHashMap. This wouldn't be as easy if you were usingHashtable.
Since synchronization is not an issue for you, I'd recommend
HashMap. If synchronization becomes an issue, you may also look atConcurrentHashMap.本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报