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

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

  4. 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 …

  5. 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 …

  6. java - List.of () or Collections.emptyList () - Stack Overflow

    Collections.emptyList() does not need to create a new object for each call; it's typical, as in OpenJDK, to just return the singleton EMPTY_LIST object. Additionally, it's clearer that you intend to mean an …

  7. 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 (the one …

  8. 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 …

  9. 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: Iterating through a Collection (here ArrayList) For some reason, I actually looked at the autocompl...

  10. ¿Cuál es la función de la clase Collections en Java?

    Jul 6, 2017 · Collections.sort(tasks, comparadorFecha); //ok showTask(); } Ahora sí, comparadorFecha, y comparadorPrioridad deben ser instancias de alguna clase que implemente la interfaz …