About 7,090,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. A Java collection of value pairs? (tuples?) - Stack Overflow

    Eclipse Collections If you're using pairs that contain primitives, Eclipse Collections provides some very efficient primitive pair classes that will avoid all the inefficient auto-boxing and auto …

  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 Array Sort descending? - Stack Overflow

    Nov 8, 2009 · 37 It's not directly possible to reverse sort an array of primitives (i.e., int[] arr = {1, 2, 3};) using Arrays.sort() and Collections.reverseOrder() because those methods require …

  6. How to sort List of objects by some property - Stack Overflow

    Collections.sort(list, comparator); In general, it's a good idea to implement Comparable<T> if there's a single "natural" sort order... otherwise (if you happen to want to sort in a particular …

  7. Java Immutable Collections - Stack Overflow

    Unmodifiable collections are usually read-only views (wrappers) of other collections. You can't add to, remove from or clear them, but the underlying collection can change. Immutable …

  8. What is a java collection? - Stack Overflow

    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 …

  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. What is the difference between Collection and List in Java?

    Jul 23, 2010 · 3 Collection is the main interface of Java Collections hierarchy and List (Sequence) is one of the sub interfaces that defines an ordered collection.