1.

 public static void main(String[] args) {
System.out.println(getEmailSuffix("jim_chen28270@163.com")); // 163.com
System.out.println(getEmailSuffix("@qq.com")); //qq.com
} private static String getEmailSuffix(String email) {
email = defaultIfBlank(email,"").trim();
if (!email.isEmpty()) {
int index = email.indexOf('@') + 1;
if (index < email.length()) {
return email.substring(index).toLowerCase();
}
}
return "";
} public static <T extends CharSequence> T defaultIfBlank(final T str, final T defaultStr) {
return isBlank(str) ? defaultStr : str;
} public static boolean isBlank(final CharSequence cs) {
int strLen;
if (cs == null || (strLen = cs.length()) == 0) {
return true;
}
for (int i = 0; i < strLen; i++) {
if (!Character.isWhitespace(cs.charAt(i))) {
return false;
}
}
return true;
}
}

2. 优化,封装到一个公用的字符串操作类中去

 public static String getEmailSuffix(String email) {
email = MyStringUtils.defaultIfBlank(email,"").trim();
if (!email.isEmpty()) {
int index = email.indexOf('@') + 1;
if (index < email.length()) {
return email.substring(index).toLowerCase();
}
}
return "";
} //自己封装的字符串操作类
class MyStringUtils {
public static <T extends CharSequence> T defaultIfBlank(final T str, final T defaultStr) {
return isBlank(str) ? defaultStr : str;
} public static boolean isBlank(final CharSequence cs) {
int strLen;
if (cs == null || (strLen = cs.length()) == 0) {
return true;
}
for (int i = 0; i < strLen; i++) {
if (!Character.isWhitespace(cs.charAt(i))) {
return false;
}
}
return true;
} public static boolean isNotBlank(final CharSequence cs) {
return !isBlank(cs);
} public static String defaultString(Object obj) {
return obj == null ? "" : obj.toString();
}
}

sell- 获取邮箱的后缀的更多相关文章

  1. 爬虫获取邮箱,存入数据库,发送邮件java Mail

    在网页上获取邮箱: package com.my.test; import java.io.BufferedReader; import java.io.InputStreamReader; impo ...

  2. 获取邮箱使用情况、以及最后一次logon时间

    # 每天收发邮件数 # https://gallery.technet.microsoft.com/scriptcenter/Count-sent-and-recceived-f9c66cf7 # 获 ...

  3. Python tldextract模块准确获取域名和后缀

    Python tldextract 模块 - 功能说明 tldextract准确地从URL的域名和子域名分离通用顶级域名或国家顶级域名. 例如,http://www.google.com,你只想取出连 ...

  4. Java获取文件的后缀名。

    /** * 详细步骤 */ private static void test1() { //获取文件的原始名称 String originalFilename = "tim.g (1).jp ...

  5. C#获取图片的后缀名

    最近在学习过程中遇到一个问题,就是如何获取图片的格式,对于一张知道全路径的照片,如果其路径包含后缀名的话,要取得后缀名,只需要一行代码即可: var ext = System.IO.Path.GetE ...

  6. FileUtils【获取SD卡根目录、读写文件、移动、复制、删除文件、获取文件名、后缀名操作类】

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 封装了获取SD卡根目录路径.以及对文件读写.获取文件名等相关操作. 因为需要用到android.permission.READ_EX ...

  7. .net 获取邮箱邮件列表和内容

    需求: 最近项目里遇到了个问题,对方没有提供直接获取数据源的api接口,而是通过邮件发数据的.这就需要接收邮件后解析邮件内容获得数据. 分析: 想在代码里实时获取邮件,可以通过邮件的几个协议来实现,常 ...

  8. novell.directory.ldap获取邮箱活动目录

    在windows系统上可以使用下列方法来查找所有的员工邮箱和员工组: StringDictionary ReturnArray = new StringDictionary(); Dictionary ...

  9. php获取文件名和后缀名

    php获取文件名 1 function retrieve($url) 2 { 3 preg_match('/\/([^\/]+\.[a-z]+)[^\/]*$/',$url,$match); 4 re ...

  10. JS 根据文件路径获取名字和后缀名

    var fileName = this.from.doc.substring(this.from.doc.lastIndexOf('/')+1); //文件名           var extNam ...

随机推荐

  1. xfce4桌面自动整理脚本

    转自http://blog.chinaunix.net/uid-22101074-id-91073.html (有修改) xfce4桌面没有自动排列的功能,如果文件多了,超出了桌面的范围,就不好找了, ...

  2. NOIP200406合并果子

    试题描述 在一个果园里,多多已经将所有的果子打了下来,而且按果子的不同种类分成了不同的堆.多多决定把所有的果子合成一堆.    每一次合并,多多可以把两堆果子合并到一起,消耗的体力等于两堆果子的重量之 ...

  3. 小问题,小细节要注意(string类型转换为bool类型)

    一个表中的推荐字段是bit类型的,添加的时候推荐有两个值,如<asp:RadioButtonList ID="RadioButtonList1" runat="se ...

  4. shell 循环

    for循环: 批量删除.gz结尾的文件: 循环打包文件并备份到一个目录下面: find ./ -maxdepth 1 -name "*.gz" find ./ -maxdepth ...

  5. MySQL中的datetime与timestamp比较-------转载

    原文地址http://database.51cto.com/art/200905/124240.htm MySQL中的datetime与timestamp比较 本文将通过实例比较MySQL中的date ...

  6. WPF 中Frame + Page 的使用

    1 在window 的设计的时候 ,中间需要进行页面切换的时候,顶一个Frame <Frame Name="MainPage"  NavigationUIVisibility ...

  7. virt-XXX

    尽管 virt-manager 是 libvirt 虚拟化 API 的一个首要用户,但有一个越来越庞大的工具生态系统在使用此接口进行虚拟化管理.virt-manager 包提供了一个便捷的 GUI,用 ...

  8. ci获取当前url链接的分组,控制器,方法

    public function role() { $ci= &get_instance();//ci控制器超级对象,就是把所有执行的方法打印出来 $directory = substr($ci ...

  9. velocity学习记录

    一.引入文件 静态引入:#include("./footer.vm.html") 动态引入:#parse("./header.vm.html") 说明:./为v ...

  10. java数组排序问题:array.sort()是从小到大排序,那么如何从大到小排序?

    别告诉我从i=a.length开始打印然后i--!因为数组没变啊,只是打印顺序变了.有木有啥别的方法,除了冒泡插入选择.. nteger [] array=new Integer[]{1,2,3,4, ...