I'm writing a program where a user can input something like
add 5 2
or
define foo
Right now the only way I know to handle this input is a bunch of if/else if statements, ie
if(args[0] == "add") add();
else if (args[0] == "define") define();
else print("Command not found.");
Is there a better way to do this, or maybe some sort of data structure/algorithm that's standard for these types of inputs? I'm using Java specifically, but I'd prefer a language-agnostic answer if possible. Thanks!