Scanner hasNextLong() Method in Java

If we are required to check, whether or not, the data entered by the user, is of type long, we can make use of the hasNextLong method. This method is going to return true if the data entered by the user is of type long. Otherwise, the return value is false.

Checking if the user input is long type(hasNextLong method)

Let’s have a look at an example, where we are trying to demonstrate the hasNextLong method →

package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
boolean storeslong = scanner.hasNextLong();
System.out.println(storeslong);
}
}

So, if you try implementing the above program and give some input that is in the range of type long, this method is going to return true, else it is going to return false.