Its a sample method about how to format a person's name. Suppose if name of the person is Fernando F Torres, with Torres being the last name, then result of code run would be Torres, Fernando F.
public class SimpleNameFormat { public static void main(String[] args){ String name = formatPersonName("Torres", "Fernando", "F"); System.out.println(name); } public static String formatPersonName(String lastName, String firstName, String middleName) { StringBuffer result = new StringBuffer(""); boolean breakFlag = false; String subStr = ""; if (lastName != null) lastName = lastName.trim(); else lastName = ""; if (firstName != null) firstName = firstName.trim(); else firstName = ""; if (middleName != null) middleName = middleName.trim(); else middleName = ""; if (lastName.equals("")) { breakFlag = true; } else { result.append(lastName); subStr = ", "; } if (firstName.equals("")) { if (breakFlag == true) { return result.toString(); } } else { result.append(subStr); subStr = " "; result.append(firstName); } if (! (middleName.equals(""))) { result.append(subStr); result.append(middleName); } return result.toString(); } }