You have two questions: is there a better way to write code, and is there a more concise way to write code.
As for the more concise , this might work:
public static String getFooStr(String input) { Foo foo = lookup(input); return foo == null ? null : foo.getFooStr(); }
Relatively better . I appreciate readability for brevity any day and by a wide margin. Your original code looks good to me. What matters is what is good for you and what is easier for you to understand and debug after 3 months. I heard someone say it best - write your code so that it is easy for others to understand, and more importantly, your future self.
source share