Top "Collections" questions

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

How to get the first element of the List or Set?

I'd like to know if I can get the first element of a list or set. Which method to use?

java list collections set
How to sort an ArrayList in Java

I have a class named Fruit. I am creating a list of this class and adding each fruit in the …

java sorting collections arraylist
How can I loop through a List<T> and grab each item?

How can I loop through a List and grab each item? I want the output to look like this: Console.…

c# for-loop collections
get string value from HashMap depending on key name

I have a HashMap with various keys and values, how can I get one value out? I have a key …

java collections hashmap
Easiest way to convert a List to a Set in Java

What is the easiest way to convert a List to a Set in Java?

java collections
How to convert a Collection to List?

I am using TreeBidiMap from the Apache Collections library. I want to sort this on the values which are doubles. …

java list sorting collections apache-commons-collection
How to convert List<Integer> to int[] in Java?

This is similar to this question: How to convert int[] to Integer[] in Java? I'm new to Java. How can …

java arrays collections
Why is there no SortedList in Java?

In Java there are the SortedSet and SortedMap interfaces. Both belong to the Java Collections framework and provide a sorted …

java sorting collections
Convert JSON to Map

What is the best way to convert a JSON code as this: { "data" : { "field1" : "value1", "field2" : "value2" } } in a Java …

java json parsing collections
Iterating through a Collection, avoiding ConcurrentModificationException when removing objects in a loop

We all know you can't do the following because of ConcurrentModificationException: for (Object i : l) { if (condition(i)) { l.remove(…

java collections iteration