About 7,050,000 results
Open links in new tab
  1. Checking if a collection is empty in Java: which is the best method?

    The other advantage of using Apache commons-collections CollectionUtils.isEmpty (or CollectionUtils.isNotEmpty) is that your if condition has less branches, so it is easier to reach a …

  2. Best practice to validate null and empty collection in Java

    Oct 4, 2012 · 23 Personally, I prefer to use empty collections instead of null and have the algorithms work in a way that for the algorithm it does not matter if the collection is empty or not.

  3. What is a java collection? - Stack Overflow

    27 Usually an instance of java.util.Collection (although java.util.Map is officially also a part of the collections framework) Although the Collection interface can be implemented directly, usually …

  4. Java: Get first item from a collection - Stack Overflow

    Nov 4, 2009 · If I have a collection, such as Collection<String> strs, how can I get the first item out? I could just call an Iterator, take its first next(), then throw the Iterator away. Is there …

  5. Java Collections: which collection to use and when?

    May 12, 2014 · As we all know with Java comes the Collections API that provide us with numerous data structures that we can use. I was wondering if there is some …

  6. A Java collection of value pairs? (tuples?) - Stack Overflow

    I like how Java has a Map where you can define the types of each entry in the map, for example <String, Integer>. What I'm looking for is a type of collection where each element in the coll...

  7. java - Compact syntax for instantiating an initializing collection ...

    Dec 29, 2016 · I'm looking for a compact syntax for instantiating a collection and adding a few items to it. I currently use this syntax: Collection<String> collection = new …

  8. java - Distinct by property - Stack Overflow

    In Java 8, how can I filter a collection using the Stream API by checking the distinctness of a property of each object? For example, I have a list of Person objects and I want to remove …

  9. How do I join two lists in Java? - Stack Overflow

    Oct 10, 2008 · Avoid Apache Commons Collections. It’s not typesafe, there are no generics. Great if you use Java 1.4, but for Java 5 and above, I’d prefer Google Guava.

  10. java - Random shuffling of an array - Stack Overflow

    Oct 5, 2009 · Java collections Arrays.asList takes var-arg of type T (T ...). If you pass a primitive array (int array), asList method will infer and generate a List<int[]>, which is a one element list …