I have two Strings, each one of them can be empty (blank or empty by StringUtils definition.) I need to display them in a concatenated fashion having a simple character in between, e.g. dash, comma, etc.
For example, a person's name consists of LastName and FirstName. PrintName method should print in this fashion:
case a: both not empty
print LastName + ", " FirstName
case b: FirstName is empty
print LastName
case c: LastName is empty
print FirstName
case d: both are empty
print empty string
This is just a simple exercise, but I'm curious if there's a most efficient method in Java that requires minimum variables/memory allocation, fewer lines of code, so on and so forth... My definition of efficiency is a bit vague so if you could write down why you think it's more efficient, that would be nice.