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. BZOJ1367 [Baltic2004]sequence

    现学的左偏树...这可是道可并堆的好题目. 首先我们考虑z不减的情况: 我们发现对于一个区间[l, r],里面是递增的,则对于此区间最优解为z[i] = t[i]: 如果里面是递减的,z[l] = z ...

  2. 20145302张薇《Java程序设计》实验三报告

    20145302张薇<Java程序设计>实验三:敏捷开发与XP实践 实验内容 使用git上传代码 使用git实现代码开发实践 实现代码的重载 使用git上传代码 git init git ...

  3. 使用Spring的注解方式实现AOP

    Spring对AOP的实现提供了很好的支持.下面我们就使用Spring的注解来完成AOP做一个例子. 首先,为了使用Spring的AOP注解功能,必须导入如下几个包.aspectjrt.jar,asp ...

  4. httpclient爬取性感美图

    依赖httpclient4.2,Jsop SemeiziCrawler.java package kidbei.learn.crawler; import java.io.File; import j ...

  5. MyEclipse 10 之下Web Service 的创建和实现

    (一)Web service服务端开发 1. 新建一个Web service project, 菜单New -> Web Service Project, 2. 新建一个 Java Bean, ...

  6. hdu Can you solve this equation?

    本题是一道二分的题,核心就是mi的大小,即精度的取值.因为原函数是一个单调递增的函数,所以可以确定y的取值范围,并且在范围内的每一个y的值,一定至少存在一个x与其对应.刚开始我将取二分这个环节用一个函 ...

  7. 【液晶模块系列基础视频】3.3fatfs接口函数的使用3

    ============================= 技术论坛:http://www.eeschool.org 博客地址:http://xiaomagee.cnblogs.com 官方网店:ht ...

  8. Windows系统中Git的安装配置

    一.Git安装 1.下载 Git官网:https://git-scm.com/download/ 选择windows版本下载即可. 百度软件中心:http://rj.baidu.com/ 如官网下载不 ...

  9. 将Asset中的数据库文件拷贝出来使用

    设置保存路径 private final static String DATABASE_PATH = "/data"+ Environment.getDataDirectory() ...

  10. 使用Nsight查找CE3的渲染bug

    工作临时的接的一个小任务,查找ce3引擎修改后在绘制上出的一点bug 在代码的底层调用代码做了一些修改后,场景里的绘制的问题,因为也是刚接触CE3代码,也只能通过Nsight来查找问题了.   首先用 ...