- 浏览: 230616 次
- 性别:
- 来自: 安徽
文章分类
最新评论
-
flyfx51:
还是这文章!
Springjie接口注入 -
liubang201010:
Navicat资料大全 资料汇总 参考:http://www. ...
Navicat相关链接 -
孟钾濠:
谢谢 很需要啊
Spring-概念01 -
mikite:
mark
Spring-概念01 -
zhuzhiguosnail:
这几个链接不错,谢了。
Spring-概念01
StringUtils
- 博客分类:
- Java
一:将数组中的字符转换为一个字符串 1、 将数组中的字符转换为一个字符串 String[3] s={"a","b","c"} 2,static public String converString(String strToConv, String conv) @param strToConv 要转换的字符串 String[3] s={"a","b","c"} 二:空值处理 3,空值检测: public static boolean isEmpty(String str) @param str the String to check, may be null 判断一个字符串是否为空,空格作非空处理。 StringUtils.isEmpty(null) = true ;StringUtils.isEmpty("") = true; StringUtils.isEmpty(" ") = false; StringUtils.isEmpty("bob") = false ;StringUtils.isEmpty(" bob ") = false ; 4,非空处理: public static boolean isNotEmpty(String str) @param str the String to check, may be null 判断一个字符串是否非空,空格作非空处理. StringUtils.isNotEmpty(null) = false; StringUtils.isNotEmpty("") = false ;StringUtils.isNotEmpty(" ") = true; StringUtils.isNotEmpty("bob") = true ;StringUtils.isNotEmpty(" bob ") = true ; 5, 去空格处理 :返回去除空格后的对象,若是null,返回null public static String trim(String str) @param str the String to be trimmed, may be null 格式化一个字符串中的空格,有非空判断处理; StringUtils.trim(null) = null; StringUtils.trim("") = "" ;StringUtils.trim(" ") = ""; StringUtils.trim("abc") = "abc"; StringUtils.trim(" abc ") = "abc" ; 6,去空格处理 :返回去除空格后的对象,若是null/""/" ",返回null public static String trimToNull(String str) @param str the String to be trimmed, may be null 格式化一个字符串中的空格,有非空判断处理,如果为空返回null; StringUtils.trimToNull(null) = null ;StringUtils.trimToNull("") = null ;StringUtils.trimToNull(" ") = null ; StringUtils.trimToNull("abc") = "abc"; StringUtils.trimToNull(" abc ") = "abc"; 7,去空格处理 :返回去除空格后的对象,若是null/""/" ",返回"" public static String trimToEmpty(String str) @param str the String to be trimmed, may be null 格式化一个字符串中的空格,有非空判断处理,如果为空返回""; StringUtils.trimToEmpty(null) = "" ;StringUtils.trimToEmpty("") = "" ;StringUtils.trimToEmpty(" ") = "" ; StringUtils.trimToEmpty("abc") = "abc" ;StringUtils.trimToEmpty(" abc ") = "abc"; 三:字符串比较: 9,public static boolean equals(String str1, String str2) 判断两个字符串是否相等,有非空处理,关注大小写。 StringUtils.equals(null, null) = true; StringUtils.equals(null, "abc") = false; StringUtils.equals("abc", null) = false; StringUtils.equals("abc", "abc") = true ;StringUtils.equals("abc", "ABC") = false ; 10,public static boolean equalsIgnoreCase(String str1, String str2) 判断两个字符串是否相等,有非空处理。忽略大小写 StringUtils.equalsIgnoreCase(null, null) = true ;StringUtils.equalsIgnoreCase(null, "abc") = false ; StringUtils.equalsIgnoreCase("abc", null) = false ;StringUtils.equalsIgnoreCase("abc", "abc") = true ; StringUtils.equalsIgnoreCase("abc", "ABC") = true ; 四:IndexOf 处理 11,public static int indexOf(String str, String searchStr) @param str the String to check, may be null 返回要查找的字符串第一次所在位置,有非空处理 StringUtils.indexOf(null, *) = -1; StringUtils.indexOf(*, null) = -1 ;StringUtils.indexOf("", "") = 0 ; StringUtils.indexOf("aabaabaa", "a") = 0; StringUtils.indexOf("aabaabaa", "b") = 2 ;StringUtils.indexOf("aabaabaa", "ab") = 1; StringUtils.indexOf("aabaabaa", "") = 0 ; 12,public static int indexOf(String str, String searchStr, int startPos) @param str the String to check, may be null 返回要由指定位置开始查找的字符串第一次所在位置,有非空处理 StringUtils.indexOf(null, *, *) = -1; StringUtils.indexOf(*, null, *) = -1 ;StringUtils.indexOf("", "", 0) = 0 ; StringUtils.indexOf("aabaabaa", "a", 0) = 0 ;StringUtils.indexOf("aabaabaa", "b", 0) = 2 ;StringUtils.indexOf("aabaabaa", "ab", 0) = 1; StringUtils.indexOf("aabaabaa", "b", 3) = 5; StringUtils.indexOf("aabaabaa", "b", 9) = -1; StringUtils.indexOf("aabaabaa", "b", -1) = 2; StringUtils.indexOf("aabaabaa", "", 2) = 2 ;StringUtils.indexOf("abc", "", 9) = 3 ; 13,public static String substring(String str, int start) @param str the String to get the substring from, may be null 返回指定位置开始的字符串中的所有字符, start>0表示从左向右, start<0表示从右向左, start=0则从左第一位开始 StringUtils.substring(null, *) = null ;StringUtils.substring("", *) = "" ;StringUtils.substring("abc", 0) = "abc"; StringUtils.substring("abc", 2) = "c" ;StringUtils.substring("abc", 4) = "" ;StringUtils.substring("abc", -2) = "bc"; StringUtils.substring("abc", -4) = "abc" ; 14,public static String substring(String str, int start, int end) @param str the String to get the substring from, may be null 返回由开始位置到结束位置之间的子字符串, start>0&&end>0从左开始(包括左)到右结束(不包括右), start<0&&end<0从右开始(包括右),再向左数到end结束(包括end) StringUtils.substring(null, *, *) = null ;StringUtils.substring("", * , *) = ""; StringUtils.substring("abc", 0, 2) = "ab" ;StringUtils.substring("abc", 2, 0) = ""; StringUtils.substring("abc", 2, 4) = "c"; StringUtils.substring("abc", 4, 6) = "" ;StringUtils.substring("abc", 2, 2) = ""; StringUtils.substring("abc", -2, -1) = "b"; StringUtils.substring("abc", -4, 2) = "ab" ; Gets the substring before the first occurance of a separator. StringUtils.substringBefore(null, *) = null; StringUtils.substringBefore("", *) = ""; StringUtils.substringBefore("abc", "a") = ""; StringUtils.substringBefore("abcba", "b") = "a"; StringUtils.substringBefore("abc", "c") = "ab"; StringUtils.substringBefore("abc", "d") = "abc" ;StringUtils.substringBefore("abc", "") = "" ; StringUtils.substringBefore("abc", null) = "abc" ; 16,public static String substringAfter(String str, String separator) @param str the String to get a substring from, may be null Gets the substring after the first occurance of a separator. StringUtils.substringAfter(null, *) = null; StringUtils.substringAfter("", *) = "" ;StringUtils.substringAfter(*, null) = ""; StringUtils.substringAfter("abc", "a") = "bc"; StringUtils.substringAfter("abcba", "b") = "cba"; StringUtils.substringAfter("abc", "c") = ""; StringUtils.substringAfter("abc", "d") = "" ;StringUtils.substringAfter("abc", "") = "abc" ; 17,public static String substringBeforeLast(String str, String separator) Gets the substring before the last occurance of a separator. 返回最后一个指定字符串之前的所有字符 StringUtils.substringBeforeLast(null, *) = null ;StringUtils.substringBeforeLast("", *) = ""; StringUtils.substringBeforeLast("abcba", "b") = "abc" ;StringUtils.substringBeforeLast("abc", "c") = "ab"; StringUtils.substringBeforeLast("a", "a") = ""; StringUtils.substringBeforeLast("a", "z") = "a"; StringUtils.substringBeforeLast("a", null) = "a" ;StringUtils.substringBeforeLast("a", "") = "a"; 18,public static String substringAfterLast(String str, String separator) Gets the substring after the last occurance of a separator. The separator is not returned. StringUtils.substringAfterLast(null, *) = null; StringUtils.substringAfterLast("", *) = "" ;StringUtils.substringAfterLast(*, "") = ""; StringUtils.substringAfterLast(*, null) = "" ;StringUtils.substringAfterLast("abc", "a") = "bc" ; StringUtils.substringAfterLast("abcba", "b") = "a"; StringUtils.substringAfterLast("abc", "c") = ""; StringUtils.substringAfterLast("a", "a") = "" ;StringUtils.substringAfterLast("a", "z") = ""; 六: Replacing(字符串替换) 19,public static String replace(String text, String repl, String with) @param text text to search and replace in, may be null Replaces all occurances of a String within another String. A null reference passed to this method is a no-op. StringUtils.replace(null, *, *) = null; StringUtils.replace("", *, *) = ""; StringUtils.replace("aba", null, null) = "aba"; StringUtils.replace("aba", null, null) = "aba"; StringUtils.replace("aba", "a", null) = "aba"; StringUtils.replace("aba", "a", "") = "aba"; StringUtils.replace("aba", "a", "z") = "zbz" ; @param text text to search and replace in, may be null Replaces a String with another String inside a larger String, for the first max values of the search String. StringUtils.replace(null, *, *, *) = null; StringUtils.replace("", *, *, *) = ""; StringUtils.replace("abaa", null, null, 1) = "abaa"; StringUtils.replace("abaa", null, null, 1) = "abaa"; StringUtils.replace("abaa", "a", null, 1) = "abaa" ; StringUtils.replace("abaa", "a", "", 1) = "abaa"; StringUtils.replace("abaa", "a", "z", 0) = "abaa" ; StringUtils.replace("abaa", "a", "z", 1) = "zbaa" ;StringUtils.replace("abaa", "a", "z", 2) = "zbza"; StringUtils.replace("abaa", "a", "z", -1) = "zbzz" ; 七,Case conversion(大小写转换) 21,public static String upperCase(String str) @param str the String to upper case, may be null Converts a String to upper case as per {@link String#toUpperCase()}. A null input String returns null. StringUtils.upperCase(null) = null; StringUtils.upperCase("") = ""; StringUtils.upperCase("aBc") = "ABC" ; 22,public static String lowerCase(String str) @param str the String to lower case, may be null A null input String returns null. StringUtils.lowerCase(null) = null ;StringUtils.lowerCase("") = "" ;StringUtils.lowerCase("aBc") = "abc" ; 23,public static String capitalize(String str) 将字符串中的首字母大写 StringUtils.capitalize(null) = null; StringUtils.capitalize("") = "" ; StringUtils.capitalize("cat") = "Cat" ;StringUtils.capitalize("cAt") = "CAt" ;
StringUtil.convString(s)="a,b,c" ;
@param conv 分隔符,默认以逗号分隔
StringUtil.convString(s,"@")="a@b@c"
@return true if the String is empty or null
@return true if the String is not empty and not null
@return the trimmed string, null if null String input
@param searchStr the String to find, may be null
@return the first index of the search String
@param searchStr the String to find, may be null
@param startPos the start position, negative treated as zero
@return the first index of the search String, -1 if no match or null string input
五:子字符串处理
@param start the position to start from, negative means
count back from the end of the String by this many characters
@return substring from start position, null if null String input
@param start the position to start from, negative means
count back from the end of the String by this many characters
@param end the position to end at (exclusive), negative means
count back from the end of the String by this many characters
@return substring from start position to end positon, null if null String input
15,public static String substringBefore(String str, String separator)
@param str the String to get a substring from, may be null
@param separator the String to search for, may be null
@return the substring before the first occurance of the separator, null if null String input
The separator is not returned.
A null string input will return null.
An empty ("") string input will return the empty string.
A null separator will return the input string.
返回指定字符串之前的所有字符
@param separator the String to search for, may be null
@return the substring after the first occurance of the separator, null if null String input
The separator is not returned.
A null string input will return null.
An empty ("") string input will return the empty string.
A null separator will return the empty string if the input string is not null.
返回指定字符串之后的所有字符
The separator is not returned.
A null string input will return null.
An empty ("") string input will return the empty string.
An empty or null separator will return the input string.
A null string input will return null. An empty ("") string input will return the empty string.
An empty or null separator will return the empty string if the input string is not null.
返回最后一个指定字符串之后的所有字符
@param repl the String to search for, may be null
@param with the String to replace with, may be null
@return the text with any replacements processed, null if null String input
以指定字符串替换原来字符串的的指定字符串 ,repl是所给字符串中存在的需要被替换的字符串,with是需要被替换成的新字符串;
20,public static String replace(String text, String repl, String with, int max)
@param repl the String to search for, may be null
@param with the String to replace with, may be null
@param max maximum number of values to replace, or -1 if no maximum
@return the text with any replacements processed,null if null String input
A null reference passed to this method is a no-op.
以指定字符串最大替换原来字符串的的指定字符串,max>0从左向右到max处截止(包括max)替换0到max之间指定的repl为with
@return the upper cased String, null if null String input
将一个字符串变为大写
@return the lower cased String, null if null String input
将一个字符串转换为小写
发表评论
-
json与对象互转-1
2018-07-22 17:14 364json与对象互转-1 json文件请看:json与对象互 ... -
IpUtils
2016-12-13 09:12 367import java.net.InetAddress; ... -
成员变量和局部变量的区别
2016-09-06 15:39 302局部变量:指在程序中,只在特定过程或函数中可以访问的变量,是相 ... -
class加载时初始化变量
2016-09-06 15:26 318我现在想一个class,在项目启动的时候,自动初始化它的成员 ... -
switch case语句的用法
2016-07-26 11:14 3691.switch支持部分基本数据类型(primitiv ... -
553 authentication is required,smtp3,DdGowEDJuUGnoVZWtkIPAA--.5044S2 1448518056
2015-11-26 14:16 1231错误描述: 使用163邮箱发送邮件的功能时,后台报错 5 ... -
java根据jar包反编译后修改再打包回jar的做法
2015-09-14 13:23 863cmd进入class文件所在文件夹,比如: D:\ledS ... -
快速生成xls模板
2015-09-13 21:28 361有些时候在客户现场需要定制化一些EXCLE的开发工作,而这些 ... -
java返回存储过程异常信息
2015-09-08 14:23 422import java.sql.CallableStatem ... -
cmd运行java添加其依赖的jar
2015-07-23 22:19 578假如java文件MyClass依赖的两个jar文件分别放在d ... -
java.util.Observable观察者模式
2015-06-24 17:29 355先举列子,对Observable有点感觉.... 观察者为 ... -
org.apache.commons.lang.StringUtils
2015-05-26 17:02 485//org.apache.commons.lang.Stri ... -
日期格式2013-09-06T19:25:12.836+10:00转换
2015-05-13 15:12 718怎么把new Date()格式化成:2013-09-06T1 ... -
LinkedHashSet-有序&去重
2015-01-27 16:45 431List<String> list = n ... -
sourceAry---取最早开始时间
2015-01-18 10:47 400/**抓取切割之后的一级包材工位序号最早开始时间*/ / ... -
返回相差天数
2015-01-18 10:36 395public static long getDistDat ... -
返回相差秒
2015-01-18 10:34 348public static long getDistDate ... -
sourceAry---冒泡排序
2014-11-29 15:16 304public static void main(String ... -
char数组转换成int数组
2014-11-29 14:34 516public class Test { publ ... -
double 类型转化为Integer
2014-11-11 15:54 498(1)把double先转化成int类型 ...
相关推荐
继承了org.apache.commons.lang3.StringUtils工具类,加入了部分常用方法,使用时直接添加到项目的公共utils下,同时在pom.xml加入依赖: <!-- ...
java获取客户端ip(经过多次代理)提示StringUtils cannot be resolved 需要先 import org.apache.commons.lang3.StringUtils; /* 内含 common-lang3.jar commons-lang3-3.9-bin.zip commons-lang3-3.9-src.zip ...
org.apache.commons.lang3.StringUtils的jar包,判断字符串为空
StringUtils 源码,使用的是commons-lang3-3.1包。 以下是StringUtils的各项用法StringUtils的各项用法
commons-lang3-3.1 StringUtils字符串jar包 org.apache.commons.lang3.StringUtils的jar包
StringUtils.java 基于commons-lang-2.5.jar提取 附带使用文档StringUtils.doc
StringUtils方法的操作对象是java.lang.String类型的对象,是JDK提供的String类型操作方法的补充,并且是null安全的(即如果输入参数String为null则不会抛出NullPointerException,而是做了相应处理,例如,如果输入...
StringUtils jar包,让你更好判断非空字符,对象等等。 记得好评哦
StringUtils(最新的哦)
org.apache.commons.lang3.StringUtils.jar,打开是common-lang3.jar文件,以及使用方法,根据使用方法使用即可,绝对可靠
StringUtils工具类的使用工具类的使用
StringUtils (Lang 2_3 API)
StringUtils.java StringUtils.java
StringUtils 方法的操作对象是 Java.lang.String 类型的对象,是 JDK 提供的 String 类型操作方法的补充,并且是 null 安全的(即如果输入参数 String 为 null 则不会抛出 NullPointerException ,而是做了相应处理,...
包含有org.apache.commons.lang3.StringUtils; org.apache.commons.lang3.reflect.FieldUtils等类