hasNext
has variation hasNext(regex)
which can be applied to check if next token matches regex, but it is limited to only one token. You would have to use delimiter which could allow you to have tokens build from two worlds. Such delimiter can look like this
sc.useDelimiter("(?<!\\G\\S+)\\s+");//delimiter representing "every second space"
(you can find explanation of this regex in Extracting pairs of words using String.split() ).
This will allow you to use hasNext("\\d+\\s+\\d+")
which will check if next token is number, space, number.
After your test is complete you can set delimiter to standard one if you are interested in reading single word tokens later.
Code example
String data = "foo 12 32 bar";
Scanner sc = new Scanner(data);
Pattern delimiter = sc.delimiter();//default delimiter
System.out.println(sc.next());//foo
sc.useDelimiter("(?<!\\G\\S+)\\s+");//delimiter representing "every second space"
System.out.println(sc.hasNext("\\d+\\s+\\d+"));//TRUE
sc.useDelimiter(delimiter);//reset delimiter
System.out.println(sc.nextInt());//12
System.out.println(sc.nextInt());//32
System.out.println(sc.next());//bar
but my program requires that nothing else was in the String.
If you are interested in checking if entire string (not just some part of it) is two numbers than you can simply use
yourString.matches("\\d+\\s+\\d+")