Tabnine Logo
Iterator.remove
Code IndexAdd Tabnine to your IDE (free)

How to use
remove
method
in
java.util.Iterator

Best Java code snippets using java.util.Iterator.remove (Showing top 20 results out of 70,506)

Refine searchRefine arrow

  • Iterator.hasNext
  • Iterator.next
  • Set.iterator
  • List.iterator
  • Map.Entry.getValue
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: stackoverflow.com

 List<String> list = new ArrayList<>();

// This is a clever way to create the iterator and call iterator.hasNext() like
// you would do in a while-loop. It would be the same as doing:
//     Iterator<String> iterator = list.iterator();
//     while (iterator.hasNext()) {
for (Iterator<String> iterator = list.iterator(); iterator.hasNext();) {
  String string = iterator.next();
  if (string.isEmpty()) {
    // Remove the current element from the iterator and the list.
    iterator.remove();
  }
}
origin: iluwatar/java-design-patterns

private void processPendingCommands() {
 Iterator<Runnable> iterator = pendingCommands.iterator();
 while (iterator.hasNext()) {
  Runnable command = iterator.next();
  command.run();
  iterator.remove();
 }
}
origin: google/guava

@CollectionSize.Require(ONE)
@CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
public void testEntrySetIteratorRemove() {
 Set<Entry<K, V>> entrySet = getMap().entrySet();
 Iterator<Entry<K, V>> entryItr = entrySet.iterator();
 assertEquals(e0(), entryItr.next());
 entryItr.remove();
 assertTrue(getMap().isEmpty());
 assertFalse(entrySet.contains(e0()));
}
origin: google/guava

public void testTransformRemove() {
 List<String> list = Lists.newArrayList("1", "2", "3");
 Iterator<String> input = list.iterator();
 Iterator<Integer> iterator =
   Iterators.transform(
     input,
     new Function<String, Integer>() {
      @Override
      public Integer apply(String from) {
       return Integer.valueOf(from);
      }
     });
 assertEquals(Integer.valueOf(1), iterator.next());
 assertEquals(Integer.valueOf(2), iterator.next());
 iterator.remove();
 assertEquals(asList("1", "3"), list);
}
origin: google/guava

@CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
@CollectionSize.Require(absent = ZERO)
public void testIterator_removeAffectsBackingCollection() {
 int originalSize = collection.size();
 Iterator<E> iterator = collection.iterator();
 Object element = iterator.next();
 // If it's an Entry, it may become invalid once it's removed from the Map. Copy it.
 if (element instanceof Entry) {
  Entry<?, ?> entry = (Entry<?, ?>) element;
  element = mapEntry(entry.getKey(), entry.getValue());
 }
 assertTrue(collection.contains(element)); // sanity check
 iterator.remove();
 assertFalse(collection.contains(element));
 assertEquals(originalSize - 1, collection.size());
}
origin: google/guava

public void testCycleRemoveWithoutNext() {
 Iterator<String> cycle = Iterators.cycle("a", "b");
 assertTrue(cycle.hasNext());
 try {
  cycle.remove();
  fail("no exception thrown");
 } catch (IllegalStateException expected) {
 }
}
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: skylot/jadx

public static void remove(List<InsnNode> list, InsnNode insn) {
  for (Iterator<InsnNode> iterator = list.iterator(); iterator.hasNext(); ) {
    InsnNode next = iterator.next();
    if (next == insn) {
      iterator.remove();
      return;
    }
  }
}
origin: google/guava

/** Clears the iterator using its remove method. */
static void clear(Iterator<?> iterator) {
 checkNotNull(iterator);
 while (iterator.hasNext()) {
  iterator.next();
  iterator.remove();
 }
}
origin: google/guava

 @CollectionSize.Require(SEVERAL)
 @CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
 public void testAsMapEntrySetIteratorRemovePropagatesToMultimap() {
  resetContainer(Helpers.mapEntry(k0(), v0()), Helpers.mapEntry(k0(), v3()));
  Set<Entry<K, Collection<V>>> asMapEntrySet = multimap().asMap().entrySet();
  Iterator<Entry<K, Collection<V>>> asMapEntryItr = asMapEntrySet.iterator();
  asMapEntryItr.next();
  asMapEntryItr.remove();
  assertTrue(multimap().isEmpty());
 }
}
origin: ReactiveX/RxJava

@Test(expected = UnsupportedOperationException.class)
public void toFlowableIterableRemove() {
  @SuppressWarnings("unchecked")
  Iterable<? extends Flowable<Integer>> f = SingleInternalHelper.iterableToFlowable(Arrays.asList(Single.just(1)));
  Iterator<? extends Flowable<Integer>> iterator = f.iterator();
  iterator.next();
  iterator.remove();
}
origin: google/guava

@Override
public boolean retainAll(Collection<?> collection) {
 Iterator<Entry<K, V>> entryItr = unfiltered.entrySet().iterator();
 boolean result = false;
 while (entryItr.hasNext()) {
  Entry<K, V> entry = entryItr.next();
  if (predicate.apply(entry) && !collection.contains(entry.getValue())) {
   entryItr.remove();
   result = true;
  }
 }
 return result;
}
origin: redisson/redisson

  @Override
  public void accept(List<T> bucket) {
    Iterator<List<T>> it = buckets.iterator();
    while (it.hasNext()) {
      List<T> itBucket = it.next();
      if (bucket == itBucket) {
        it.remove();
        broadcastNext(bucket);
        break;
      }
    }
  }
};
origin: stackoverflow.com

 Iterator<Map.Entry<String,String>> iter = TestMap.entrySet().iterator();
while (iter.hasNext()) {
  Map.Entry<String,String> entry = iter.next();
  if("Sample".equalsIgnoreCase(entry.getValue())){
    iter.remove();
  }
}
origin: google/guava

public void testIdentityKeySetIteratorRemove() {
 BiMap<Integer, String> bimap =
   new AbstractBiMap<Integer, String>(
     new IdentityHashMap<Integer, String>(), new IdentityHashMap<String, Integer>()) {};
 bimap.put(1, "one");
 bimap.put(2, "two");
 bimap.put(3, "three");
 Iterator<Integer> iterator = bimap.keySet().iterator();
 iterator.next();
 iterator.next();
 iterator.remove();
 iterator.next();
 iterator.remove();
 assertEquals(1, bimap.size());
 assertEquals(1, bimap.inverse().size());
}
origin: google/guava

@Override
public boolean removeAll(Collection<?> collection) {
 Iterator<Entry<K, V>> entryItr = unfiltered.entrySet().iterator();
 boolean result = false;
 while (entryItr.hasNext()) {
  Entry<K, V> entry = entryItr.next();
  if (predicate.apply(entry) && collection.contains(entry.getValue())) {
   entryItr.remove();
   result = true;
  }
 }
 return result;
}
origin: skylot/jadx

private static void removeInsn(MethodNode mth, BlockNode block, PhiInsn phiInsn) {
  Iterator<InsnNode> it = block.getInstructions().iterator();
  while (it.hasNext()) {
    InsnNode insn = it.next();
    if (insn == phiInsn) {
      it.remove();
      return;
    }
  }
  LOG.warn("Phi node not removed: {}, mth: {}", phiInsn, mth);
}
origin: google/guava

/**
 * Deletes and returns the next value from the iterator, or returns {@code null} if there is no
 * such value.
 */
static <T> @Nullable T pollNext(Iterator<T> iterator) {
 if (iterator.hasNext()) {
  T result = iterator.next();
  iterator.remove();
  return result;
 } else {
  return null;
 }
}
origin: google/guava

public void testBiMapEntrySetIteratorRemove() {
 BiMap<Integer, String> map = HashBiMap.create();
 map.put(1, "one");
 Set<Entry<Integer, String>> entries = map.entrySet();
 Iterator<Entry<Integer, String>> iterator = entries.iterator();
 Entry<Integer, String> entry = iterator.next();
 entry.setValue("two"); // changes the iterator's current entry value
 assertEquals("two", map.get(1));
 assertEquals(Integer.valueOf(1), map.inverse().get("two"));
 iterator.remove(); // removes the updated entry
 assertTrue(map.isEmpty());
}
java.utilIteratorremove

Javadoc

Removes the last object returned by next from the collection. This method can only be called once between each call to next.

Popular methods of Iterator

  • next
  • hasNext
    Returns true if there is at least one more element, false otherwise.
  • forEachRemaining
  • <init>

Popular in Java

  • Making http post requests using okhttp
  • addToBackStack (FragmentTransaction)
  • getSharedPreferences (Context)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • PrintStream (java.io)
    Fake signature of an existing Java class.
  • UnknownHostException (java.net)
    Thrown when a hostname can not be resolved.
  • Collections (java.util)
    This class consists exclusively of static methods that operate on or return collections. It contains
  • ResourceBundle (java.util)
    ResourceBundle is an abstract class which is the superclass of classes which provide Locale-specifi
  • HttpServlet (javax.servlet.http)
    Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site. A sub
  • Join (org.hibernate.mapping)
  • Top Vim plugins
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