title: Creating a simple String parser, Interactive Shell-like
body: <p>I want to make a simple interative shell based on the console where I can write commands like <code>login</code>, <code>help</code>, et cetera.</p>
  
  <p>I first thought of using Enums, but then I didn't know how to implement them neatly without a load of if-else statements, so I decided to go with an array-approach and came up with this:</p>
  
  <pre><code>public class Parser {
      private static String[] opts = new String[] {"opt0", "opt1", "opt2", "opt3" ... }
  
      public void parse(String text) {
          for(int i = 0; i &lt; opts.length; i++) {
              if(text.matches(opts[i]) {
                  switch(i) {
                      case 0:
                          // Do something
  
                      case 1:
                          // Do something-something
  
                      case 2:
                          // Do something else
                  }
  
               return;
              }
          }
      }
  }
  </code></pre>
  
  <p>But I ended up seeing that this was probably the most rudimentary way of doing something like this, and that there would be problems if I wanted to change the order of the options. How could I make a simpler parser? This way it would work, but it would also have said problems. The use of the program is purely educational, not intended for any serious thing.</p>