Here you can find the source of toStreamNumber(final Scanner scanner)
public static Stream<Long> toStreamNumber(final Scanner scanner)
//package com.java2s; import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Objects; import java.util.Scanner; import java.util.Spliterator; import java.util.Spliterators; import java.util.stream.Stream; import java.util.stream.StreamSupport; public class Main { public static Stream<Long> toStreamNumber(final Scanner scanner) { Objects.requireNonNull(scanner); final Iterator<Long> iter = new Iterator<Long>() { final Scanner s = scanner; @Override//from w w w . j a v a2s.c o m public boolean hasNext() { boolean hasNumber = false; while (s.hasNext()) { hasNumber = s.hasNextLong(); if (hasNumber) { return true; } s.next(); } return false; } @Override public Long next() { if (!hasNext()) { throw new NoSuchElementException(); } return s.nextLong(); } }; return StreamSupport.stream( Spliterators.spliteratorUnknownSize(iter, Spliterator.ORDERED | Spliterator.NONNULL), false); } }