About 1,530,000 results
Open links in new tab
  1. java - Getting the difference between two sets - Stack Overflow

    Java 8 We can make use of removeIf which takes a predicate to write a utility method as: // computes the difference without modifying the sets public static <T> Set<T> …

  2. How to convert an Array to a Set in Java - Stack Overflow

    I would like to convert an array to a Set in Java. There are some obvious ways of doing this (i.e. with a loop) but I would like something a bit neater, something like: java.util.Arrays.asList(Obj...

  3. Easiest way to convert a List to a Set in Java - Stack Overflow

    8 With Java 10, you could now use Set#copyOf to easily convert a List<E> to an unmodifiable Set<E>: Example: var set = Set.copyOf(list); Keep in mind that this is an unordered operation, …

  4. java - How to sort a HashSet? - Stack Overflow

    In case you move a HashSet to TreeSet, your class must implement Comparable interface or provide a custom Comparator. Otherwise, since you cannot sort a HashSet, just convert it into …

  5. java - How to initialize HashSet values by construction ... - Stack ...

    Jan 11, 2010 · NOTE: Some answers omit `new HashSet<T> (int initialCapacity) parameter, if you already know the size of the collection use it.

  6. How to Iterate over a Set/HashSet without an Iterator?

    Feb 13, 2017 · This was introduced to facilitate functional programming with Java 8. Convert to an Array and traverse Apart from that, in the Collection API, you can find the toArray methods, …

  7. java - Why there is no ConcurrentHashSet against …

    Aug 9, 2011 · 727 HashSet is based on HashMap. If we look at HashSet<E> implementation, everything is been managed under HashMap<E,Object>. <E> is used as a key of HashMap. …

  8. What is the time complexity performance of HashSet.contains () in …

    The worst-case performance of contains will be O (log n) for Java 8, and O (n) for Java 7, but average case closer to O (1). This is because the hashset is backed by a hashmap, and thus …

  9. Different types of thread-safe Sets in Java - Stack Overflow

    Apr 8, 2021 · There seems to be a lot of different implementations and ways to generate thread-safe Sets in Java. Some examples include 1) CopyOnWriteArraySet 2) …

  10. Union or intersection of Java Sets - Stack Overflow

    Jun 30, 2018 · What is the simplest way to make a union or an intersection of Sets in Java? I've seen some strange solutions to this simple problem (e.g. manually iterating the two sets).