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. 创建 maven 本地仓库; (五)

    在 pom.xml 添加依赖包的时候,有时候会提示无法从 http://repo1.maven.org/maven2/ 获取的情况,这时可配置个本地仓库: 从网上下载 maven 仓库网站源码包 Ne ...

  2. Ubuntu SSH root user cannot login

    Open /etc/ssh/sshd_config and check if PermitRootLogin is set to yes. If not, then set it to yes and ...

  3. 如何使用数据库保存session的方法简介

    使用数据库保存session的方法 php的session默认是以文件方式保存在服务器端,并且在客户端使用cookie保存变量,这就会出现一个问题,当一个用户由于某种安全原因关闭了浏览器的cookie ...

  4. 找到n中最小的k个数

    题目:n个数中,求最小的前k个数. 这道题在各个地方都看到过,在国内出现的频率也非常高. 面完阿里回来听说这道题又被考了,所以还是决定回来写一写,对于这种高频题...顺便再吐槽一下阿里的面试,我竟然一 ...

  5. Robocopy

    用法: http://technet.microsoft.com/zh-cn/library/cc733145%28v=ws.10%29.aspx   图形化工具: http://sourceforg ...

  6. css实现文字过长省略显示

    .simpleName { width:110px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; } <div cl ...

  7. 用thinkphp进行微信开发的整体设计思考

    用thinkphp进行微信开发的整体设计思考 http://www.2cto.com/weixin/201504/388423.html 2015-04-09      0个评论       作者:明 ...

  8. Ruby--Array

    --后面连接其它数组:[ARRAY].concat([OTHER ARRAY]) --排序:sort,进阶:sort_by{|obj| obj.[VALUE]} --随机获取:[ARRAY].samp ...

  9. overflow样式修改插件——jscrollpane

    官网:http://jscrollpane.kelvinluck.com/

  10. 【转】Unity3D中脚本的执行顺序和编译顺序(vs工程引用关系)

    http://www.cnblogs.com/champ/p/execorder.html 在Unity中可以同时创建很多脚本,并且可以分别绑定到不同的游戏对象上,它们各自都在自己的生命周期中运行.与 ...