简体   繁体   中英

Java ArrayList, Hashmap instead of Vector, Hashtable

I read in the Oracle docs that Vector and Hashtable are Legacy. ArrayList is preferred over Vector. And Hashmap is preferred over Hashtable. I am still relatively new in Java.. Can someone confirm to me that this is indeed the generally accepted practice? Are there places people still use Vector? Thank you

https://docs.oracle.com/javase/8/docs/api/java/util/Hashtable.html https://docs.oracle.com/javase/tutorial/collections/implementations/index.html

Don't trust us random Internet denizens, trust the javadocs.

The relevant parts outlined :

Unlike the new collection implementations, Hashtable is synchronized. If a thread-safe implementation is not needed, it is recommended to use HashMap in place of Hashtable.

- https://docs.oracle.com/javase/8/docs/api/java/util/Hashtable.html

Unlike the new collection implementations, Vector is synchronized. If a thread-safe implementation is not needed, it is recommended to use ArrayList in place of Vector.

-https://docs.oracle.com/javase/8/docs/api/java/util/Vector.html

Of course parallelism (of which thread safety is an aspect) is handled in a whole different way nowadays, so that property on those collections is far less desirable than it once was.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM