目录

StringUtil类

import java.io.UnsupportedEncodingException;

/**
* 字符串工具
*/
public class StringUtil { /**
* 比较两个字符串(大小写敏感)。
* <pre>
* StringUtil.equals(null, null) = true
* StringUtil.equals(null, "abc") = false
* StringUtil.equals("abc", null) = false
* StringUtil.equals("abc", "abc") = true
* StringUtil.equals("abc", "ABC") = false
* </pre>
*
* @param str1 要比较的字符串1
* @param str2 要比较的字符串2
*
* @return 如果两个字符串相同,或者都是<code>null</code>,则返回<code>true</code>
*/
public static boolean equals(String str1, String str2) {
if (str1 == null) {
return str2 == null;
} return str1.equals(str2);
}
// Empty checks
//-----------------------------------------------------------------------
/**
* <p>Checks if a CharSequence is empty ("") or null.</p>
* <pre>
* StringUtils.isEmpty(null) = true
* StringUtils.isEmpty("") = true
* StringUtils.isEmpty(" ") = false
* StringUtils.isEmpty("bob") = false
* StringUtils.isEmpty(" bob ") = false
* </pre>
* @param cs the CharSequence to check, may be null
* @return {@code true} if the CharSequence is empty or null
*/
public static boolean isEmpty(CharSequence cs) {
return cs == null || cs.length() == 0;
} /**
* <p>Checks if a CharSequence is not empty ("") and not null.</p>
*
* <pre>
* StringUtils.isNotEmpty(null) = false
* StringUtils.isNotEmpty("") = false
* StringUtils.isNotEmpty(" ") = true
* StringUtils.isNotEmpty("bob") = true
* StringUtils.isNotEmpty(" bob ") = true
* </pre>
*
* @param cs the CharSequence to check, may be null
* @return {@code true} if the CharSequence is not empty and not null
*/
public static boolean isNotEmpty(CharSequence cs) {
return !StringUtils.isEmpty(cs);
} /**
* <p>Checks if a CharSequence is whitespace, empty ("") or null.</p>
*
* <pre>
* StringUtils.isBlank(null) = true
* StringUtils.isBlank("") = true
* StringUtils.isBlank(" ") = true
* StringUtils.isBlank("bob") = false
* StringUtils.isBlank(" bob ") = false
* </pre>
* @param cs the CharSequence to check, may be null
* @return {@code true} if the CharSequence is null, empty or whitespace
* @since 2.0
*/
public static boolean isBlank(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)) == false) {
return false;
}
}
return true;
} /**
* <p>Checks if a CharSequence is not empty (""), not null and not whitespace only.</p>
*
* <pre>
* StringUtils.isNotBlank(null) = false
* StringUtils.isNotBlank("") = false
* StringUtils.isNotBlank(" ") = false
* StringUtils.isNotBlank("bob") = true
* StringUtils.isNotBlank(" bob ") = true
* </pre>
* @param cs the CharSequence to check, may be null
* @return {@code true} if the CharSequence is
* not empty and not null and not whitespace
*/
public static boolean isNotBlank(CharSequence cs) {
return !StringUtils.isBlank(cs);
} /**
* @param content 需要加密串
* @param charset 字符集
* @return 加密后的字节数组
*/
public static byte[] getContentBytes(String content, String charset) {
if (StringUtils.isEmpty(charset)) {
return content.getBytes();
}
try {
return content.getBytes(charset);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("转码过程中出现错误,指定的编码集不对,您目前指定的编码集是:" + charset);
}
} }

最新文章

  1. gulp入门小记
  2. iOS MJRefresh下拉刷新(上拉加载)使用详解
  3. A题进行时--浙大PAT 1011-1020
  4. C# DataGridView绑定数据源的几种常见方式
  5. Windows系统下用命令行编译C/C++程序过程总结
  6. Gherkin学习笔记
  7. sublime支持显示中文
  8. LINQ基础(三)
  9. tensorflow学习笔记1:导出和加载模型
  10. intval — 获取变量的整数值
  11. python入门学习:9.文件和异常
  12. ElasticSearch6.5.0 【字段类型】
  13. 【转】ArcGIS10的附件功能
  14. 201621123018《Java程序设计》第9周学习报告
  15. Python爬取简书主页信息
  16. C# 字符串的操作
  17. (转)GCT之逻辑经验总结(拿来主义)
  18. Spring学习12-Spring利用mock进行单元测试
  19. Some Principles
  20. [搬运]CORBA中BOA和POA的含义

热门文章

  1. 洛谷 P1053 解题报告
  2. Maven Scope 依赖范围
  3. javascript中!=、!==、==、===操作符总结
  4. 网上整理的对于Rest和Restful api的理解
  5. golang自定义路由控制实现(二)-流式注册接口以及支持RESTFUL
  6. jquery选择器 看这个链接吧!2017.6.2
  7. repr调试python程序
  8. Java系列2 --- 你真的知道Java的String对象么?
  9. RabbitMQ分布式集群架构和高可用性(HA)
  10. pymysql和 SQLAlchemy在python下的使用