Basic lexical analyzer for addition and multiplication in Java
<p>I would like to make a very simple lexical analyzer but I am a bit stuck.
Let's say I have only two arithmetic operations (addition and multiplication) and two integers. An addition or a multiplication is made with the two operands (the order does not matter since it's an addition or multiplication). 
For example as input <code>"ADD 4 8"</code>, is expected 4+8. 
Below is what I've done so far. I can extract the operands, but curiously not the operator either <code>"+"</code> or <code>"*"</code>.
As stated, I don't really know how to go forward, and perform a simple add or mul.Thanks for your help.</p>

<pre><code>private static enum Type {
    ADD, MUL, OPERAND
}

private static class Token&lt;TokenType, TokenValue&gt; {
    private final TokenType type;
    private final TokenValue value;

    public Token(TokenType t, TokenValue value) {
        this.type = t;
        this.value = value;
    }

    public String toString() {
        return "Token value: " + this.value + "\n" + "Token type: " + this.type;
    }
}

private static String getOperand(String operand, int index) {

    int i = index;
    while (i &lt; operand.length()) {
        if (Character.isDigit(operand.charAt(i))) {
            i++;
        } else {
            return operand.substring(index, i);
        }
    }
    return operand.substring(index, i);
}

private static ArrayList&lt;Token&lt;Type, String&gt;&gt; lex(String expression) {

    ArrayList&lt;Token&lt;Type, String&gt;&gt; tokens = new ArrayList&lt;&gt;();

    for (int i = 0; i &lt; expression.length(); i++) {
        char currChar = expression.charAt(i);

        switch (currChar) {
        case '+':
            tokens.add(new Token&lt;&gt;(Type.ADD, String.valueOf(currChar)));
            i++;
            break;

        case '*':
            tokens.add(new Token&lt;&gt;(Type.MUL, String.valueOf(currChar)));
            i++;
            break;

        default:
            if (Character.isWhitespace(currChar)) {
                i++;
            } else {
                String operand = getOperand(expression, i);
                i += operand.length();
                tokens.add(new Token&lt;&gt;(Type.OPERAND, operand));
            }
            break;
        }
    }
    return tokens;
}

public static void main(String[] args) {

    Scanner scan = new Scanner(System.in);
    System.out.println("Please enter an expression: ");
    String input = scan.nextLine();

    ArrayList&lt;Token&lt;Type, String&gt;&gt; tokens = lex(input);
    for (Token token : tokens) {
        System.out.println(token);
    }
}
</code></pre>

<p>example of input : <code>"5+1"</code>
output : </p>

<pre><code>Token value: 5
Token type: OPERAND
Token value: 1
Token type: OPERAND
</code></pre>