In the below code :
import java.io.*;
import java.util.*;
class GFG {
public static void main (String[] args) {
Scanner scan = new Scanner(System.in);
if(scan.hasNext("Teddy ")){ // or if change it here to "Bear"
System.out.println("Yes its true");
}
else {
System.out.println("false");
}
}
}
As per the definition hasNext(String pattern):
Returns true if the next token matches the pattern constructed from the specified string. The scanner does not advance past any input.
- I'm not able to get an idea of what are tokens for java and if whitespaces are included in tokens
What's the point I'm not able to get for hasNext(String pattern)
Input:
Teddy Bear
output:
False