Scanner.nextLong() has the following syntax.
public long nextLong()
In the following code shows how to use Scanner.nextLong() method.
import java.util.Scanner; /*from w ww . ja v a2 s.c om*/ public class Main { public static void main(String[] args) { String s = "java2s.com 1 + 1 = 2.0 true "; Long l = 123456789098765432L; s = s + l; Scanner scanner = new Scanner(s); while (scanner.hasNext()) { System.out.println("Not Found :" + scanner.next()); if (scanner.hasNextLong()) { System.out.println("Found :" + scanner.nextLong()); } } scanner.close(); } }
The code above generates the following result.