Tags » Iterator

Java - Iterator, Iterable

Iterator

An Iterator is an interface which allows iterating over collection
It provides hasNext() and next() methods to iterate as shown below –

Iterator lists= Arrays.asList("A","B","C").iterator();
		while(lists.hasNext()) {
			System.out.println(lists.next());
		}
… 140 more words
Java

Java - Convert Iterator to Stream

Use Spliterators.spliterator() or Spliterators.spliteratorUnknownSize() to convert an iterator to a stream

 

package com.pwn.stream;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

public class IteratorToStream {

	public static void main(String[] args) {

		Iterator<String> iterator = Arrays.asList("A", "B", "C")
				.iterator();
		Spliterator<String> spliterator = Spliterators
				.spliteratorUnknownSize(iterator, 0);
		Stream<String> stream = StreamSupport.stream(spliterator,
				false);
		stream.forEach(System.out::println);

	}
}
A
B
C
Java

Using Cursors with MyBatis

There are queries that you shouldn’t map as List<T>.

And the Cursor comes to play.

@Service
public class SomeService {

    public Cursor<Some> getCursor(...) {
        // returns the cursor? 170 more words
Programming

Iterable interface - enable for-each

This tutorial explains how to implement java.lang.Iterable<T> on a class to enable for-each loop based iteration through the collection of objects stored in that class. 617 more words

Enumeration and Iterator

Both Enumeration and Iterator is used for traversing through the underlying Collection. Enumeration can traverse limited collection such as Vectors and HashTable. Whereas Iterator can be used to almost all the  421 more words

fail-fast Vs fail-safe

Java provides the iterator to iterate the objects in the Collection. The rule is that the Collection should not be altered when iterating, if modified you will get the  … 367 more words

Even Fibonacci numbers

Rust Language implementation for project euler problem 2 named “Even Fibonacci numbers”

Each new term in the Fibonacci sequence is generated by adding the previous two terms.

32 more words
2