In php, one can handle a list of state names and their abbreviations with an associative array like this:
Another way of doing it in Java. Although a better way has already been posted, this one's syntactically closer to your php code.
for (String x:stateDict.keySet()){ System.out.printf("The abbreviation for %s is %s\n",x,stateDict.get(x)); }