PatternMatcher class
final Pattern LETTERS = Pattern.compile("[A-Za-z]");



Every time either getLetters or getNumbers is called, a new regex is created and compiled.

This is not very efficient, considering regex compilation can be fairly slow. I would recommend moving the compiling to the constructor. Then, you can set the new Patterns to be fields of the class.

Now, the regexes will be compiled once and only once.



I don't quite understand your design.


Initialize the class with a string.
Use the class methods to get different parts of the string.


What if I want to check another string? Well, considering the fact that you made inputString public, I'm assuming you want the code to just set inputString to something else:

myPatternMatcher.inputString = 


Just to quickly say, the inputString should be private and there should be a setter for it. This is common Java practice.

However, that is not the point of this tip. My main point is that it is weird that I have to change a property of the class and then call another method of that class to work on the string I just passed in a second ago.

With setters, that would look like this:

myPatternMatcher.setInputString("foo");
myPatternMatcher.getLetters();


Isn't that a little weird having to call another method just to use the class?

I think a better approach would be to make the methods static. You could get rid of having to pass the inputString via the constructor, and you can move the pattern compilation to the fields themselves. Then, for each method, you can have it accept the string to check.

Now, your class would look like this:

public class PatternMatcher {
    public static String getLetters(String str) {
        ...
    }
    public static String getNumbers(String str) {
        ...
    }
}


Now, to use this class, it would look something like this:

PatternMatcher.getLetters("Foo");


This design makes more sense.