Java tutorial
import java.util.Scanner; public class Main { public static void main(String[] args) { String s = "Hello true World! 1 + 1 = 2.0 "; Scanner scanner = new Scanner(s); while (scanner.hasNext()) { // if the next is boolean, print found and the boolean if (scanner.hasNextBoolean()) { System.out.println("Found :" + scanner.nextBoolean()); } // if a boolean is not found, print "Not Found" and the token System.out.println("Not Found :" + scanner.next()); } scanner.close(); } }