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(); } }
@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(); }
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(); } } }
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(); }
/** * 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); }
/** * 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(); }