/** * 获取模糊的手机号码 * @param phone * @return */ public static String getPhone(String phone2){ return phone2.substring(0,3) + "****" + phone2.substring(7, phone2.length()); } public static String getEmail(String email){ if(email.indexOf("@")<-1){ return ""; } String emailname=email.substring(0, email.indexOf("@")); String emailAddress=email.substring(email.indexOf("@"),email.length()); //后缀名字 if(emailname.length()>4){ return emailname.substring(0, emailname.length()-4) +"****"+emailAddress; }else{ return "****"+emailAddress; } } public static void main(String[] args) { String phone2 = "15988888888"; System.out.println(phone2); String email="hrccc@javaweb.top"; System.out.println(StringUtil.getEmail(email)); }