Top "Collections" questions

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

Remove elements from collection while iterating

AFAIK, there are two approaches: Iterate over a copy of the collection Use the iterator of the actual collection For …

java collections iteration
How to get a reversed list view on a list in Java?

I want to have a reversed list view on a list (in a similar way than List#sublist provides a …

java list collections iterator reverse
How to convert Set to Array?

Set seems like a nice way to create Arrays with guaranteed unique elements, but it does not expose any good …

javascript arrays collections syntax ecmascript-harmony
Most efficient way to increment a Map value in Java

I hope this question is not considered too basic for this forum, but we'll see. I'm wondering how to refactor …

java optimization collections
How to copy a java.util.List into another java.util.List

I have a List<SomeBean> that is populated from a Web Service. I want to copy/clone the …

java collections copy
How to copy Java Collections list

I have an ArrayList and I want to copy it exactly. I use utility classes when possible on the assumption …

java list collections copy
How to sort a HashSet?

For lists, we use the Collections.sort(List) method. What if we want to sort a HashSet?

java sorting collections set hashset
Difference between <? super T> and <? extends T> in Java

What is the difference between List<? super T> and List<? extends T> ? I used to use …

java generics collections
Difference between HashSet and HashMap?

Apart from the fact that HashSet does not allow duplicate values, what is the difference between HashMap and HashSet? I …

java collections hashmap hashset
Java: Best way to iterate through a Collection (here ArrayList)

Today I was happily coding away when I got to a piece of code I already used hundreds of times: …

java collections for-loop