问题
Everything in Java seems to follow capitalization rules except for Hashtable.
Hashtable<String, String> ht = new Hashtable<String, String>();
as opposed to
ArrayList<String> a = new ArrayList<String>();
or
HashMap<String,Integer> a = new HashMap<String,Integer>();
Why is this ? Is Hash Table read as just one word (Hashtable) ?
回答1:
Hashtable
was created in Java v1. The consistent naming conventions for collections were established later, in Java2, when the other classes were published as part of the brand new Java Collection Framework.
Which btw made Hashtable
obsolete, so it should not be used in new code.
Hope that helps.
回答2:
Although this question has no technical value, I have to admit, I've asked myself this a couple of times :)
My version is that unlike List (ArrayList), Set (HashSet) , Map (Tree/HashMap) table is not a data structure.
Of course (its possibly known) that the Hashtable class was created before the collection framework (in java 1.0). So maybe at that point they didn't really thought about the same naming conventions. In general we better use collection framework from java 2+ :)
来源:https://stackoverflow.com/questions/12506706/why-is-the-t-in-hash-tablehashtable-in-java-not-capitalized