Avoid APIs from Pre-History
Summary
Do not use Vector
, StringBuffer
and other archaic parts of the JDK.
Details
Java has been around for over 20 years. In order to maintain backwards compatibility, it has hoarded all manner of APIs that no longer make sense to use. Some of them are handily marked with @Deprecated annotation, others are not.
Unfortunately, many are still used in university courses and online examples. New Java programmers may not be aware they have been replaced - a few to watch out for include:
java.util.Vector
- useArrayList
insteadjava.lang.StringBuffer
- useStringBuilder
insteadjava.util.Stack
- use aDequeue
(e.g.ArrayDeqeue
)java.util.Hashtable
- use aMap
(e.g.HashMap
)java.util.Enumeration
- use anIterator
or anIterable
Each of these replacements (except Enumeration
) differ from the originals by not being synchronized. If you think you need a synchronized collection go away somewhere quiet and think again.