About 12,000,000 results
Open links in new tab
  1. 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.

  2. 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 collection/tutorial/advice that could …

  3. 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 good …

  4. 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 client code will use …

  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 reference types …

  6. How to filter a Java Collection (based on predicate)?

    229 Assuming that you are using Java 1.5, and that you cannot add Google Collections, I would do something very similar to what the Google guys did. This is a slight variation on Jon's comments. …

  7. java - What is the Simplest Way to Reverse an ArrayList ... - Stack ...

    May 26, 2012 · final List<T> result = new ArrayList<>(list); Collections.reverse(result); return result; } This approach works, but requires iterating over the list twice. The copy constructor (new …

  8. How to count the number of occurrences of an element in a List

    Feb 3, 2009 · 8 Actually, Collections class has a static method called : frequency (Collection c, Object o) which returns the number of occurrences of the element you are searching for, by the way, this will …

  9. collections - Easiest way to convert a List to a Set in Java - Stack ...

    12 Remember that, converting from List to Set will remove duplicates from collection because List supports duplicates but Set does not support duplicates in Java. Direct Conversion : The most …

  10. How to use Comparator in Java to sort - Stack Overflow

    Collections.sort(list, comparator); If you are using Java 7 or below then you can use a comparator for customized sorting order by implementing compare method. For example: