Tabnine Logo
Set.iterator
Code IndexAdd Tabnine to your IDE (free)

How to use
iterator
method
in
java.util.Set

Best Java code snippets using java.util.Set.iterator (Showing top 20 results out of 118,224)

Refine searchRefine arrow

  • Iterator.hasNext
  • Iterator.next
  • Map.Entry.getValue
  • Map.Entry.getKey
  • Map.entrySet
origin: stackoverflow.com

 public static void printMap(Map mp) {
  Iterator it = mp.entrySet().iterator();
  while (it.hasNext()) {
    Map.Entry pair = (Map.Entry)it.next();
    System.out.println(pair.getKey() + " = " + pair.getValue());
    it.remove(); // avoids a ConcurrentModificationException
  }
}
origin: google/guava

 static <K, V> Entry<K, V> mapEntry(K key, V value) {
  return Collections.singletonMap(key, value).entrySet().iterator().next();
 }
}
origin: square/okhttp

 @Override public void deleteContents(File directory) throws IOException {
  String prefix = directory.toString() + "/";
  for (Iterator<File> i = files.keySet().iterator(); i.hasNext(); ) {
   File file = i.next();
   if (file.toString().startsWith(prefix)) i.remove();
  }
 }
}
origin: iluwatar/java-design-patterns

/**
 * Checkout object from pool
 */
public synchronized T checkOut() {
 if (available.isEmpty()) {
  available.add(create());
 }
 T instance = available.iterator().next();
 available.remove(instance);
 inUse.add(instance);
 return instance;
}
origin: google/guava

@MapFeature.Require(SUPPORTS_REMOVE)
public void testClear() {
 getMap().clear();
 assertTrue("After clear(), a map should be empty.", getMap().isEmpty());
 assertEquals(0, getMap().size());
 assertFalse(getMap().entrySet().iterator().hasNext());
}
origin: google/guava

/**
 * A sensible definition of {@link #isEmpty} in terms of the {@code iterator} method of {@link
 * #entrySet}. If you override {@link #entrySet}, you may wish to override {@link #isEmpty} to
 * forward to this implementation.
 *
 * @since 7.0
 */
protected boolean standardIsEmpty() {
 return !entrySet().iterator().hasNext();
}
origin: stackoverflow.com

 Map<Integer, Integer> map = new HashMap<Integer, Integer>();
Iterator<Map.Entry<Integer, Integer>> entries = map.entrySet().iterator();
while (entries.hasNext()) {
  Map.Entry<Integer, Integer> entry = entries.next();
  System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
}
origin: google/guava

/**
 * Called after {@link #successorIterator} is exhausted. Advances {@link #node} to the next node
 * and updates {@link #successorIterator} to iterate through the successors of {@link #node}.
 */
protected final boolean advance() {
 checkState(!successorIterator.hasNext());
 if (!nodeIterator.hasNext()) {
  return false;
 }
 node = nodeIterator.next();
 successorIterator = graph.successors(node).iterator();
 return true;
}
origin: google/guava

public static <K, V> Entry<K, V> mapEntry(K key, V value) {
 return Collections.singletonMap(key, value).entrySet().iterator().next();
}
origin: square/okhttp

 @Override public void testRunFinished(Result result) throws Exception {
  Thread.setDefaultUncaughtExceptionHandler(oldDefaultUncaughtExceptionHandler);
  System.err.println("Uninstalled aggressive uncaught exception handler");

  synchronized (exceptions) {
   if (!exceptions.isEmpty()) {
    throw Throwables.rethrowAsException(exceptions.keySet().iterator().next());
   }
  }
 }
}
origin: google/guava

private static void assertEmpty(Set<? extends List<?>> set) {
 assertTrue(set.isEmpty());
 assertEquals(0, set.size());
 assertFalse(set.iterator().hasNext());
}
origin: stackoverflow.com

 Map map = new HashMap();
Iterator entries = map.entrySet().iterator();
while (entries.hasNext()) {
  Map.Entry entry = (Map.Entry) entries.next();
  Integer key = (Integer)entry.getKey();
  Integer value = (Integer)entry.getValue();
  System.out.println("Key = " + key + ", Value = " + value);
}
origin: spring-projects/spring-framework

@Override
public String toString() {
  Iterator<Map.Entry<String, Object>> entries = entrySet().iterator();
  StringBuilder sb = new StringBuilder("{");
  while (entries.hasNext()) {
    Map.Entry<String, Object> entry = entries.next();
    sb.append(entry.getKey());
    sb.append('=');
    sb.append(valueToString(entry.getValue()));
    sb.append(entries.hasNext() ? ", " : "");
  }
  sb.append("}");
  return sb.toString();
}
origin: hankcs/HanLP

  public String getMostLikelyLabel()
  {
    return labelMap.entrySet().iterator().next().getKey();
  }
}
origin: google/guava

static <K extends Enum<K>> Class<K> inferKeyType(Map<K, ?> map) {
 if (map instanceof EnumBiMap) {
  return ((EnumBiMap<K, ?>) map).keyType();
 }
 if (map instanceof EnumHashBiMap) {
  return ((EnumHashBiMap<K, ?>) map).keyType();
 }
 checkArgument(!map.isEmpty());
 return map.keySet().iterator().next().getDeclaringClass();
}
origin: google/guava

public void testEmptyRangeSubMultiset(SortedMultiset<E> multiset) {
 assertTrue(multiset.isEmpty());
 assertEquals(0, multiset.size());
 assertEquals(0, multiset.toArray().length);
 assertTrue(multiset.entrySet().isEmpty());
 assertFalse(multiset.iterator().hasNext());
 assertEquals(0, multiset.entrySet().size());
 assertEquals(0, multiset.entrySet().toArray().length);
 assertFalse(multiset.entrySet().iterator().hasNext());
}
origin: google/guava

@Override
public boolean remove(Object o) {
 Iterator<Entry<K, V>> entryItr = unfiltered.entrySet().iterator();
 while (entryItr.hasNext()) {
  Entry<K, V> entry = entryItr.next();
  if (predicate.apply(entry) && Objects.equal(entry.getValue(), o)) {
   entryItr.remove();
   return true;
  }
 }
 return false;
}
origin: alibaba/druid

public void clear() {
  Iterator<Entry<PreparedStatementKey, PreparedStatementHolder>> iter = map.entrySet().iterator();
  while (iter.hasNext()) {
    Entry<PreparedStatementKey, PreparedStatementHolder> entry = iter.next();
    closeRemovedStatement(entry.getValue());
    iter.remove();
  }
}
origin: google/guava

public void testEntrySetSetValueSameValue() {
 // TODO: Investigate the extent to which, in practice, maps that support
 // put() also support Entry.setValue().
 if (!supportsPut) {
  return;
 }
 final Map<K, V> map;
 try {
  map = makePopulatedMap();
 } catch (UnsupportedOperationException e) {
  return;
 }
 Set<Entry<K, V>> entrySet = map.entrySet();
 Entry<K, V> entry = entrySet.iterator().next();
 final V oldValue = entry.getValue();
 final V returnedValue = entry.setValue(oldValue);
 assertEquals(oldValue, returnedValue);
 assertTrue(entrySet.contains(mapEntry(entry.getKey(), oldValue)));
 assertEquals(oldValue, map.get(entry.getKey()));
 assertInvariants(map);
}
origin: google/guava

@MapFeature.Require({FAILS_FAST_ON_CONCURRENT_MODIFICATION, SUPPORTS_REMOVE})
@CollectionSize.Require(SEVERAL)
public void testRemovePresentConcurrentWithKeySetIteration() {
 try {
  Iterator<K> iterator = getMap().keySet().iterator();
  getMap().remove(k0());
  iterator.next();
  fail("Expected ConcurrentModificationException");
 } catch (ConcurrentModificationException expected) {
  // success
 }
}
java.utilSetiterator

Javadoc

Returns an iterator on the elements of this set. The elements are unordered.

Popular methods of Set

  • add
    Adds the specified element to this set if it is not already present (optional operation). More forma
  • contains
    Returns true if this set contains the specified element. More formally, returns true if and only if
  • size
  • isEmpty
    Returns true if this set contains no elements.
  • addAll
    Adds all of the elements in the specified collection to this set if they're not already present (opt
  • remove
    Removes the specified element from this set if it is present (optional operation). More formally, re
  • toArray
    Returns an array containing all of the elements in this set; the runtime type of the returned array
  • stream
  • clear
    Removes all of the elements from this set (optional operation). The set will be empty after this cal
  • removeAll
    Removes from this set all of its elements that are contained in the specified collection (optional o
  • forEach
  • equals
    Compares the specified object with this set for equality. Returnstrue if the specified object is als
  • forEach,
  • equals,
  • containsAll,
  • retainAll,
  • hashCode,
  • removeIf,
  • parallelStream,
  • spliterator,
  • of

Popular in Java

  • Making http requests using okhttp
  • runOnUiThread (Activity)
  • setContentView (Activity)
  • getSharedPreferences (Context)
  • Connection (java.sql)
    A connection represents a link from a Java application to a database. All SQL statements and results
  • NoSuchElementException (java.util)
    Thrown when trying to retrieve an element past the end of an Enumeration or Iterator.
  • Queue (java.util)
    A collection designed for holding elements prior to processing. Besides basic java.util.Collection o
  • ReentrantLock (java.util.concurrent.locks)
    A reentrant mutual exclusion Lock with the same basic behavior and semantics as the implicit monitor
  • HttpServletRequest (javax.servlet.http)
    Extends the javax.servlet.ServletRequest interface to provide request information for HTTP servlets.
  • FileUtils (org.apache.commons.io)
    General file manipulation utilities. Facilities are provided in the following areas: * writing to a
  • Top plugins for WebStorm
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