Skip to content

Instantly share code, notes, and snippets.

@iamcrypticcoder
Last active April 18, 2018 17:15
Show Gist options
  • Save iamcrypticcoder/dbeb1f5d779ab86e8ab8e33b14da905a to your computer and use it in GitHub Desktop.
Save iamcrypticcoder/dbeb1f5d779ab86e8ab8e33b14da905a to your computer and use it in GitHub Desktop.
public class FunctionDemo {
static Function<String, String> shortName = (s) -> {
if (null == s || s.length() == 0) return "Unknown";
String[] splits = s.split(" ");
String ret = splits[0];
if (splits.length >= 2) ret += " " + splits[1].substring(0, 1) + ".";
return ret;
};
public static void main(String... args) {
System.out.println(shortName.apply("Kazi Mahbubur Rahman"));
System.out.println(shortName.apply("Adam Smith"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment