Skip to content

Instantly share code, notes, and snippets.

@khannedy
Created September 2, 2013 12:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khannedy/6412416 to your computer and use it in GitHub Desktop.
Save khannedy/6412416 to your computer and use it in GitHub Desktop.
NameHelper.getLastName
package com.wordpress.eecchhoo.javaholic.helper;
/**
* @author Eko Khannedy
*/
public class NameHelper {
/**
* Get last name from full name, if full name is
* Eko Khannedy, then last name is Khannedy.
*
* @param name full name
* @return String of last name
*/
public static String getLastName(String name) {
if (name == null) {
return null;
}
String[] split = name.split(" ");
if (split.length < 2) {
return null;
}
return split[split.length - 1];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment