Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> It is worth noting that Hashtable was not originally part of the Collections framework.

An other class in that case being Vector, and that's the reason why they have a lot of duplication in their methods: they have the original ones, and they have the new ones coming from the Collections framework interface (this is also the source of having both Iterator[0] and Enumerable[1] in the JDK: Iterator is the Collections framework iterator interface, Enumerable is the pre-Collections one)

An other big difference, which you hinted at, is that Hashtable and Vector are both synchronized collections (method calls will take the collection lock and behave "atomically"), whereas Collections framework classes are not, instead the Collections framework has compositional wrappers[2] which provide this behavior independently of the underlying collection implementation.

finally, a little trick for more fluent Collections initialization: you can abuse anonymous subclasses and instance initializers to get something much less imperative:

    List<String> myList = new ArrayList<String>() {{
        add("Second Thing");
        add("Second Thing");
        add("First Thing");
    }};
[0] http://docs.oracle.com/javase/6/docs/api/java/util/Iterator....

[1] http://docs.oracle.com/javase/6/docs/api/java/util/Enumerati...

[2] http://docs.oracle.com/javase/6/docs/api/java/util/Collectio...



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: