Top "Collections" questions

Collections APIs provide developers with a set of classes and interfaces that make it easier to handle collections of objects.

Initialization of an ArrayList in one line

I wanted to create a list of options for testing purposes. At first, I did this: ArrayList<String> …

java collections arraylist initialization
How do I efficiently iterate over each entry in a Java Map?

If I have an object implementing the Map interface in Java and I wish to iterate over every pair contained …

java dictionary collections iteration
How to make a new List in Java

We create a Set as: Set myset = new HashSet() How do we create a List in Java?

java list collections
What are the differences between a HashMap and a Hashtable in Java?

What are the differences between a HashMap and a Hashtable in Java? Which is more efficient for non-threaded applications?

java collections hashmap hashtable
Sort a Map<Key, Value> by values

I am relatively new to Java, and often find that I need to sort a Map<Key, Value> …

java sorting dictionary collections
How to directly initialize a HashMap (in a literal way)?

Is there some way of initializing a Java HashMap like this?: Map<String,String> test = new HashMap<…

java dictionary collections initialization
When to use LinkedList over ArrayList in Java?

I've always been one to simply use: List<String> names = new ArrayList<>(); I use the interface …

java arraylist collections linked-list
How to sort an ArrayList?

I have a List of doubles in java and I want to sort ArrayList in descending order. Input ArrayList is …

java sorting arraylist collections
How to convert comma-separated String to List?

Is there any built-in method in Java which allows us to convert comma separated String to some container (e.g …

java string collections split
Ways to iterate over a list in Java

Being somewhat new to the Java language I'm trying to familiarize myself with all the ways (or at least the …

java loops collections iteration