Programming Tips - Java: What collections do you prefer?

Date: 2013aug30 Updated: 2020aug4 Language: Java Q. Java: What collections do you prefer? A. There are many collections classes but it pays to use a limited number. One good reason: so you can pass results from one function to another. Single-threaded:
java.util.ArrayList - growable array java.util.HashMap - hash (associative array) java.util.Stack - stack java.util.HashSet - set (check if something is a member) java.util.TreeSet - case insensitive set java.util.TreeMap - case insensitive hash
Multi-threaded:
java.util.concurrent.LinkedBlockingQueue - queue for communication between threads java.util.concurrent.ConcurrentHashMap - better than Hashtable
In general, use java.util.concurrent over the older synchronized collections. Immutable: https://docs.oracle.com/javase/9/core/creating-immutable-lists-sets-and-maps.htm#JSCOR-GUID-ECD1A3C5-14A7-47E2-995E-40C9B6B935C4