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 count the number of occurrences of an element in a List

I have an ArrayList, a Collection class of Java, as follows: ArrayList<String> animals = new ArrayList<String&…

java arraylist collections
Easy way to convert Iterable to Collection

In my application I use 3rd party library (Spring Data for MongoDB to be exact). Methods of this library return …

java collections
How can I turn a List of Lists into a List in Java 8?

If I have a List<List<Object>>, how can I turn that into a List<…

java collections java-8
MongoDB Show all contents from all collections

Is it possible to show all collections and its contents in MongoDB? Is the only way to show one by …

mongodb collections find
Best practice to validate null and empty collection in Java

I want to verify whether a collection is empty and null. Could anyone please let me know the best practice. …

java collections
LINQ .Any VS .Exists - What's the difference?

Using LINQ on collections, what is the difference between the following lines of code? if(!coll.Any(i => i.…

c# linq collections
Java 8 Distinct by property

In Java 8 how can I filter a collection using the Stream API by checking the distinctness of a property of …

java collections java-8 java-stream distinct-values
What is the Simplest Way to Reverse an ArrayList?

What is the simplest way to reverse this ArrayList? ArrayList<Integer> aList = new ArrayList<>(); //Add elements …

java android arraylist collections
Best way to convert list to comma separated string in java

I have Set<String> result & would like to convert it to comma separated string. My approach would …

java string list collections set
Get nth character of a string in Swift programming language

How can I get the nth character of a string? I tried bracket([]) accessor with no luck. var string = "Hello, …

swift string collections character