Java tutorial
//package com.java2s; public class Main { public static String nameFromEmail(String email) { if (isEmptyTrimmed(email) || !email.contains("@")) { return email; } int atIndex = email.indexOf("@"); return email.substring(0, atIndex); } public static boolean isEmptyTrimmed(String str) { return (isNull(str) || str.trim().length() == 0); } public static boolean isNull(String str) { return str == null; } }