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

How to use
hasNext
method
in
java.util.Iterator

Best Java code snippets using java.util.Iterator.hasNext (Showing top 20 results out of 193,833)

Refine searchRefine arrow

  • Iterator.next
  • List.iterator
  • Set.iterator
  • Iterator.remove
  • List.add
  • Collection.iterator
  • 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: google/guava

public void testAdvance_pastEnd() {
 List<String> list = newArrayList();
 list.add("a");
 list.add("b");
 Iterator<String> iterator = list.iterator();
 advance(iterator, 5);
 assertFalse(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: 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: prestodb/presto

public synchronized void finishSplits(int splits)
{
  List<Map.Entry<PlanNodeId, Split>> toRemove = new ArrayList<>();
  Iterator<Map.Entry<PlanNodeId, Split>> iterator = this.splits.entries().iterator();
  while (toRemove.size() < splits && iterator.hasNext()) {
    toRemove.add(iterator.next());
  }
  for (Map.Entry<PlanNodeId, Split> entry : toRemove) {
    this.splits.remove(entry.getKey(), entry.getValue());
  }
  updateSplitQueueSpace();
}
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

public void testIteratorMinExhaustsIterator() {
 List<Integer> ints = Lists.newArrayList(9, 0, 3, 5);
 Iterator<Integer> iterator = ints.iterator();
 assertEquals(0, (int) numberOrdering.min(iterator));
 assertFalse(iterator.hasNext());
}
origin: google/guava

private static void assertEmpty(Set<? extends List<?>> set) {
 assertTrue(set.isEmpty());
 assertEquals(0, set.size());
 assertFalse(set.iterator().hasNext());
}
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

/**
 * Splits {@code sequence} into string components and returns them as an immutable list. If you
 * want an {@link Iterable} which may be lazily evaluated, use {@link #split(CharSequence)}.
 *
 * @param sequence the sequence of characters to split
 * @return an immutable list of the segments split from the parameter
 * @since 15.0
 */
@Beta
public List<String> splitToList(CharSequence sequence) {
 checkNotNull(sequence);
 Iterator<String> iterator = splittingIterator(sequence);
 List<String> result = new ArrayList<>();
 while (iterator.hasNext()) {
  result.add(iterator.next());
 }
 return Collections.unmodifiableList(result);
}
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: google/guava

public void testGet_basic() {
 List<String> list = newArrayList();
 list.add("a");
 list.add("b");
 Iterator<String> iterator = list.iterator();
 assertEquals("b", get(iterator, 1));
 assertFalse(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: spring-projects/spring-framework

/**
 * Return a string representation of the given list of {@code HttpRange} objects.
 * <p>This method can be used to for an {@code Range} header.
 * @param ranges the ranges to create a string of
 * @return the string representation
 */
public static String toString(Collection<HttpRange> ranges) {
  Assert.notEmpty(ranges, "Ranges Collection must not be empty");
  StringBuilder builder = new StringBuilder(BYTE_RANGE_PREFIX);
  for (Iterator<HttpRange> iterator = ranges.iterator(); iterator.hasNext(); ) {
    HttpRange range = iterator.next();
    builder.append(range);
    if (iterator.hasNext()) {
      builder.append(", ");
    }
  }
  return builder.toString();
}
origin: apache/incubator-dubbo

  public static <T> void printList(List<T> list) {
    Log.info("PrintList:");
    Iterator<T> it = list.iterator();
    while (it.hasNext()) {
      Log.info(it.next().toString());
    }

  }
}
java.utilIteratorhasNext

Javadoc

Returns true if there is at least one more element, false otherwise.

Popular methods of Iterator

  • next
  • remove
  • forEachRemaining
  • <init>

Popular in Java

  • Running tasks concurrently on multiple threads
  • getSupportFragmentManager (FragmentActivity)
  • getApplicationContext (Context)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • Kernel (java.awt.image)
  • PrintWriter (java.io)
    Wraps either an existing OutputStream or an existing Writerand provides convenience methods for prin
  • MalformedURLException (java.net)
    This exception is thrown when a program attempts to create an URL from an incorrect specification.
  • PriorityQueue (java.util)
    A PriorityQueue holds elements on a priority heap, which orders the elements according to their natu
  • Modifier (javassist)
    The Modifier class provides static methods and constants to decode class and member access modifiers
  • XPath (javax.xml.xpath)
    XPath provides access to the XPath evaluation environment and expressions. Evaluation of XPath Expr
  • 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