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

How to use
next
method
in
java.util.Iterator

Best Java code snippets using java.util.Iterator.next (Showing top 20 results out of 226,926)

Refine searchRefine arrow

  • Iterator.hasNext
  • List.iterator
  • Set.iterator
  • Iterator.remove
  • Collection.iterator
  • List.add
  • Map.Entry.getValue
  • Map.Entry.getKey
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: iluwatar/java-design-patterns

 /**
  * Collects the remaining objects of the given iterator into a List.
  * 
  * @return a new List with the remaining objects.
  */
 public static <E> List<E> toList(Iterator<E> iterator) {
  List<E> copy = new ArrayList<>();
  while (iterator.hasNext()) {
   copy.add(iterator.next());
  }
  return copy;
 }
}
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: google/guava

 public void testIteratorNoSuchElementException() {
  Iterator<E> iterator = collection.iterator();
  while (iterator.hasNext()) {
   iterator.next();
  }

  try {
   iterator.next();
   fail("iterator.next() should throw NoSuchElementException");
  } catch (NoSuchElementException expected) {
  }
 }
}
origin: spring-projects/spring-framework

@Override
public String getPath() {
  StringBuilder pathBuilder = new StringBuilder();
  pathBuilder.append(PATH_DELIMITER);
  for (Iterator<String> iterator = this.pathSegments.iterator(); iterator.hasNext(); ) {
    String pathSegment = iterator.next();
    pathBuilder.append(pathSegment);
    if (iterator.hasNext()) {
      pathBuilder.append(PATH_DELIMITER);
    }
  }
  return pathBuilder.toString();
}
origin: apache/kafka

public void clean() {
  // the lock protects removal from a concurrent put which could otherwise mutate the
  // queue after it has been removed from the map
  synchronized (unsent) {
    Iterator<ConcurrentLinkedQueue<ClientRequest>> iterator = unsent.values().iterator();
    while (iterator.hasNext()) {
      ConcurrentLinkedQueue<ClientRequest> requests = iterator.next();
      if (requests.isEmpty())
        iterator.remove();
    }
  }
}
origin: google/guava

public void testAdvance_basic() {
 List<String> list = newArrayList();
 list.add("a");
 list.add("b");
 Iterator<String> iterator = list.iterator();
 advance(iterator, 1);
 assertEquals("b", iterator.next());
}
origin: google/guava

@CollectionFeature.Require(FAILS_FAST_ON_CONCURRENT_MODIFICATION)
@ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)
public void testAddAtIndexConcurrentWithIteration() {
 try {
  Iterator<E> iterator = collection.iterator();
  getList().add(0, e3());
  iterator.next();
  fail("Expected ConcurrentModificationException");
 } catch (ConcurrentModificationException expected) {
  // success
 }
}
origin: google/guava

private static <V extends Enum<V>> Class<V> inferValueType(Map<?, V> map) {
 if (map instanceof EnumBiMap) {
  return ((EnumBiMap<?, V>) map).valueType;
 }
 checkArgument(!map.isEmpty());
 return map.values().iterator().next().getDeclaringClass();
}
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

public void testSize_partiallyConsumed() {
 Iterator<Integer> iterator = asList(1, 2, 3, 4, 5).iterator();
 iterator.next();
 iterator.next();
 assertEquals(3, Iterators.size(iterator));
}
origin: iluwatar/java-design-patterns

/**
 * @return the count of remaining objects of the current Iterable
 */
public final int getRemainingElementsCount() {
 int counter = 0;
 Iterator<E> iterator = iterator();
 while (iterator.hasNext()) {
  iterator.next();
  counter++;
 }
 return counter;
}
origin: google/guava

 @CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
 @CollectionSize.Require(ONE)
 public void testValuesIteratorRemove() {
  Iterator<V> valuesItr = multimap().values().iterator();
  valuesItr.next();
  valuesItr.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: 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: iluwatar/java-design-patterns

/**
 * Transforms this FluentIterable into a new one containing objects of the type T.
 * 
 * @param function a function that transforms an instance of E into an instance of T
 * @param <T> the target type of the transformation
 * @return a new FluentIterable of the new type
 */
@Override
public final <T> FluentIterable<T> map(Function<? super E, T> function) {
 List<T> temporaryList = new ArrayList<>();
 Iterator<E> iterator = iterator();
 while (iterator.hasNext()) {
  temporaryList.add(function.apply(iterator.next()));
 }
 return from(temporaryList);
}
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: 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());
}
java.utilIteratornext

Javadoc

Returns the next object and advances the iterator.

Popular methods of Iterator

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

Popular in Java

  • Reactive rest calls using spring rest template
  • getSharedPreferences (Context)
  • findViewById (Activity)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • MessageFormat (java.text)
    Produces concatenated messages in language-neutral way. New code should probably use java.util.Forma
  • Deque (java.util)
    A linear collection that supports element insertion and removal at both ends. The name deque is shor
  • LinkedHashMap (java.util)
    LinkedHashMap is an implementation of Map that guarantees iteration order. All optional operations a
  • Notification (javax.management)
  • XPath (javax.xml.xpath)
    XPath provides access to the XPath evaluation environment and expressions. Evaluation of XPath Expr
  • Project (org.apache.tools.ant)
    Central representation of an Ant project. This class defines an Ant project with all of its targets,
  • Best IntelliJ 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