Q:

How to iterate over a string of numbers / special characters in java?

For example, take a string: "33 4 / 44 2 - ^"
I'm using Scanner to iterate over the ints but once there is no nextInt and it hits a special character, how would I go about "getting" that character and then moving onto the next int/special character? 

A:

You can check if there's a int available using hasNextInt(). If there isn't, just discard the next token by calling next():
Scanner scanner = new Scanner("33 4 / 44 2 - ^");
while (scanner.hasNext()) {
    if (scanner.hasNextInt()) {
        int nextInt = scanner.nextInt();
        System.out.println(nextInt);
    } else {
        // discard next token
        scanner.next();
    }
}

Output:
33
4
44
2

