Java - (Enumerable|Iterator) Data Type (Iterable interface)

> Procedural Languages > Java

1 - About

The (Enumeration|Iterator) interface defines the methods by which you can:

  • enumerate
  • obtain one at a time

the elements of a collection.

The Enumerator Interface:

  • has been deprecated for the use of Iterator.
  • is an external iterators
Advertising

3 - Enumerable data type

Enumerable types are class that implement the enum or iterable interface such as:

4 - toStream

Java - Stream Processing

StreamSupport.stream(iterable.spliterator(), false/true)

Example:

  • Does a string starts with a root directory ?
String s = "c:\";
Boolean isAbsolutePath = StreamSupport
      .stream(fileSystem.getRootDirectories().spliterator(), false)
      .anyMatch(p->s.startsWith(p.toString()));