Tabnine Logo
HashSet.<init>
Code IndexAdd Tabnine to your IDE (free)

How to use
java.util.HashSet
constructor

Best Java code snippets using java.util.HashSet.<init> (Showing top 20 results out of 193,977)

Refine searchRefine arrow

  • Set.add
  • Iterator.hasNext
  • Iterator.next
  • PrintStream.println
  • HashSet.add
  • Set.iterator
  • Set.contains
origin: spring-projects/spring-framework

public void registerExternallyManagedDestroyMethod(String destroyMethod) {
  synchronized (this.postProcessingLock) {
    if (this.externallyManagedDestroyMethods == null) {
      this.externallyManagedDestroyMethods = new HashSet<>(1);
    }
    this.externallyManagedDestroyMethods.add(destroyMethod);
  }
}
origin: prestodb/presto

public static <T> HashSet<T> arrayToSet(T[] elements)
{
  if (elements != null) {
    int len = elements.length;
    HashSet<T> result = new HashSet<T>(len);
    for (int i = 0; i < len; ++i) {
      result.add(elements[i]);
    }
    return result;
  }
  return new HashSet<T>();
}
origin: stackoverflow.com

 Set<String> set = new HashSet<String>();

//populate set

for (String s : set) {
  System.out.println(s);
}
origin: sohutv/cachecloud

@Override
public Set<byte[]> keySet() {
 Set<byte[]> keySet = new HashSet<byte[]>();
 Iterator<ByteArrayWrapper> iterator = internalMap.keySet().iterator();
 while (iterator.hasNext()) {
  keySet.add(iterator.next().data);
 }
 return keySet;
}
origin: apache/incubator-druid

public static Set<String> findDuplicates(Iterable<String> fieldNames)
{
 Set<String> duplicates = new HashSet<>();
 Set<String> uniqueNames = new HashSet<>();
 for (String fieldName : fieldNames) {
  String next = StringUtils.toLowerCase(fieldName);
  if (uniqueNames.contains(next)) {
   duplicates.add(next);
  }
  uniqueNames.add(next);
 }
 return duplicates;
}
origin: apache/storm

@Override
public Collection<Node> takeNodes(int nodesNeeded) {
  HashSet<Node> ret = new HashSet<>();
  Iterator<Node> it = _nodes.iterator();
  while (it.hasNext() && nodesNeeded > ret.size()) {
    Node n = it.next();
    ret.add(n);
    _totalSlots -= n.totalSlotsFree();
    it.remove();
  }
  return ret;
}
origin: stackoverflow.com

Set<Integer> mySet = new HashSet<Integer>();
mySet.add(1);
mySet.add(2);
mySet.add(3);
for (Set<Integer> s : SetUtils.powerSet(mySet)) {
  System.out.println(s);
}
origin: spring-projects/spring-framework

@Test
public void asyncResultWithSeparateCallbacksAndValue() throws Exception {
  String value = "val";
  final Set<String> values = new HashSet<>(1);
  ListenableFuture<String> future = AsyncResult.forValue(value);
  future.addCallback(values::add, (ex) -> fail("Failure callback not expected: " + ex));
  assertSame(value, values.iterator().next());
  assertSame(value, future.get());
  assertSame(value, future.completable().get());
  future.completable().thenAccept(v -> assertSame(value, v));
}
origin: apache/storm

private static Set<WorkerSlot> newlyAddedSlots(Assignment old, Assignment current) {
  Set<NodeInfo> oldSlots = new HashSet<>(old.get_executor_node_port().values());
  Set<NodeInfo> niRet = new HashSet<>(current.get_executor_node_port().values());
  niRet.removeAll(oldSlots);
  Set<WorkerSlot> ret = new HashSet<>();
  for (NodeInfo ni : niRet) {
    ret.add(new WorkerSlot(ni.get_node(), ni.get_port_iterator().next()));
  }
  return ret;
}
origin: swagger-api/swagger-core

private static List<Parameter> collectParameters(Type type, List<Annotation> annotations, Components components, javax.ws.rs.Consumes classConsumes, JsonView jsonViewAnnotation) {
  final Iterator<OpenAPIExtension> chain = OpenAPIExtensions.chain();
  return chain.hasNext() ? chain.next().extractParameters(annotations, type, new HashSet<>(), components, classConsumes, null, false, jsonViewAnnotation, chain).parameters :
      Collections.emptyList();
}
origin: stackoverflow.com

 Set<String> users = new HashSet<>(Arrays.asList("Alice", "Bob"));

System.out.println(users.contains("Alice"));
// -> prints true

System.out.println(users.contains("Jack"));
// -> prints false
origin: google/guava

private static Set<Feature<?>> computeEntrySetFeatures(Set<Feature<?>> features) {
 Set<Feature<?>> derivedFeatures = new HashSet<>();
 derivedFeatures.addAll(features);
 derivedFeatures.remove(CollectionFeature.GENERAL_PURPOSE);
 derivedFeatures.remove(CollectionFeature.SUPPORTS_ADD);
 derivedFeatures.remove(CollectionFeature.ALLOWS_NULL_VALUES);
 derivedFeatures.add(CollectionFeature.REJECTS_DUPLICATES_AT_CREATION);
 if (!derivedFeatures.remove(CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS)) {
  derivedFeatures.remove(CollectionFeature.SERIALIZABLE);
 }
 return derivedFeatures;
}
origin: jenkinsci/jenkins

@Override
protected int act(List<Run<?, ?>> builds) throws IOException {
  job.checkPermission(Run.DELETE);
  final HashSet<Integer> hsBuilds = new HashSet<>();
  for (Run<?, ?> build : builds) {
    if (!hsBuilds.contains(build.number)) {
      build.delete();
      hsBuilds.add(build.number);
    }
  }
  stdout.println("Deleted "+hsBuilds.size()+" builds");
  return 0;
}
origin: ReactiveX/RxJava

@Test
public void testFlatMapSelectorMaxConcurrent() {
  final int m = 4;
  final AtomicInteger subscriptionCount = new AtomicInteger();
  Observable<Integer> source = Observable.range(1, 10)
    .flatMap(new Function<Integer, Observable<Integer>>() {
    @Override
    public Observable<Integer> apply(Integer t1) {
      return composer(Observable.range(t1 * 10, 2), subscriptionCount, m)
          .subscribeOn(Schedulers.computation());
    }
  }, new BiFunction<Integer, Integer, Integer>() {
    @Override
    public Integer apply(Integer t1, Integer t2) {
      return t1 * 1000 + t2;
    }
  }, m);
  TestObserver<Integer> to = new TestObserver<Integer>();
  source.subscribe(to);
  to.awaitTerminalEvent();
  to.assertNoErrors();
  Set<Integer> expected = new HashSet<Integer>(Arrays.asList(
      1010, 1011, 2020, 2021, 3030, 3031, 4040, 4041, 5050, 5051,
      6060, 6061, 7070, 7071, 8080, 8081, 9090, 9091, 10100, 10101
  ));
  Assert.assertEquals(expected.size(), to.valueCount());
  System.out.println("--> testFlatMapSelectorMaxConcurrent: " + to.values());
  Assert.assertTrue(expected.containsAll(to.values()));
}
origin: jenkinsci/jenkins

private Set<UpdateSite.Warning> getActiveWarnings() {
  UpdateSiteWarningsConfiguration configuration = ExtensionList.lookupSingleton(UpdateSiteWarningsConfiguration.class);
  HashSet<UpdateSite.Warning> activeWarnings = new HashSet<>();
  for (UpdateSite.Warning warning : configuration.getApplicableWarnings()) {
    if (!configuration.getIgnoredWarnings().contains(warning.id)) {
      activeWarnings.add(warning);
    }
  }
  return Collections.unmodifiableSet(activeWarnings);
}
origin: apache/rocketmq

public Set<String> whichGroupByTopic(final String topic) {
  Set<String> groups = new HashSet<String>();
  Iterator<Entry<String, ConcurrentMap<Integer, Long>>> it = this.offsetTable.entrySet().iterator();
  while (it.hasNext()) {
    Entry<String, ConcurrentMap<Integer, Long>> next = it.next();
    String topicAtGroup = next.getKey();
    String[] arrays = topicAtGroup.split(TOPIC_GROUP_SEPARATOR);
    if (arrays.length == 2) {
      if (topic.equals(arrays[0])) {
        groups.add(arrays[1]);
      }
    }
  }
  return groups;
}
origin: spring-projects/spring-framework

private boolean isDependent(String beanName, String dependentBeanName, @Nullable Set<String> alreadySeen) {
  if (alreadySeen != null && alreadySeen.contains(beanName)) {
    return false;
  }
  String canonicalName = canonicalName(beanName);
  Set<String> dependentBeans = this.dependentBeanMap.get(canonicalName);
  if (dependentBeans == null) {
    return false;
  }
  if (dependentBeans.contains(dependentBeanName)) {
    return true;
  }
  for (String transitiveDependency : dependentBeans) {
    if (alreadySeen == null) {
      alreadySeen = new HashSet<>();
    }
    alreadySeen.add(beanName);
    if (isDependent(transitiveDependency, dependentBeanName, alreadySeen)) {
      return true;
    }
  }
  return false;
}
origin: apache/rocketmq

  public HashSet<String> queryTopicConsumeByWho(final String topic) {
    HashSet<String> groups = new HashSet<>();
    Iterator<Entry<String, ConsumerGroupInfo>> it = this.consumerTable.entrySet().iterator();
    while (it.hasNext()) {
      Entry<String, ConsumerGroupInfo> entry = it.next();
      ConcurrentMap<String, SubscriptionData> subscriptionTable =
        entry.getValue().getSubscriptionTable();
      if (subscriptionTable.containsKey(topic)) {
        groups.add(entry.getKey());
      }
    }
    return groups;
  }
}
origin: google/guava

@Override
public Set<V> removeAll(Object key) {
 Set<V> values = new HashSet<V>(2);
 if (!map.containsKey(key)) {
  return values;
 }
 values.add(map.remove(key));
 return values;
}
origin: stackoverflow.com

 Map<String, String> map = new HashMap<>();
map.put("a", "");
map.put("b", "");
map.put("c", "");

Set<String> set = new HashSet<> ();
set.add("a");
set.add("b");

map.keySet().removeAll(set);

System.out.println(map); //only contains "c"
java.utilHashSet<init>

Javadoc

Constructs a new empty instance of HashSet.

Popular methods of HashSet

  • add
    Adds the specified element to this set if it is not already present. More formally, adds the specifi
  • contains
    Returns true if this set contains the specified element. More formally, returns true if and only if
  • size
    Returns the number of elements in this set (its cardinality).
  • addAll
  • remove
    Removes the specified element from this set if it is present. More formally, removes an element e su
  • iterator
    Returns an iterator over the elements in this set. The elements are returned in no particular order.
  • isEmpty
    Returns true if this set contains no elements.
  • clear
    Removes all of the elements from this set. The set will be empty after this call returns.
  • toArray
  • removeAll
  • equals
  • clone
    Returns a shallow copy of this HashSet instance: the elements themselves are not cloned.
  • equals,
  • clone,
  • retainAll,
  • stream,
  • containsAll,
  • forEach,
  • hashCode,
  • toString,
  • removeIf

Popular in Java

  • Parsing JSON documents to java classes using gson
  • onRequestPermissionsResult (Fragment)
  • onCreateOptionsMenu (Activity)
  • startActivity (Activity)
  • LinkedList (java.util)
    Doubly-linked list implementation of the List and Dequeinterfaces. Implements all optional list oper
  • PriorityQueue (java.util)
    A PriorityQueue holds elements on a priority heap, which orders the elements according to their natu
  • TimerTask (java.util)
    The TimerTask class represents a task to run at a specified time. The task may be run once or repeat
  • ExecutorService (java.util.concurrent)
    An Executor that provides methods to manage termination and methods that can produce a Future for tr
  • Reference (javax.naming)
  • JComboBox (javax.swing)
  • Best plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now