`
nakata_yf
  • 浏览: 111786 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

StringUtil包函数

阅读更多
StringUtil包函数
一、数组转成字符串:
1、 将数组中的字符转换为一个字符串
将数组中的字符转换为一个字符串

@param strToConv 要转换的字符串 ,默认以逗号分隔
@return 返回一个字符串
String[3] s={"a","b","c"}
StringUtil.convString(s)="a,b,c"
2、 static public String converString(String strToConv)
@param strToConv 要转换的字符串 ,
@param conv 分隔符,默认以逗号分隔
@return 同样返回一个字符串

String[3] s={"a","b","c"}
StringUtil.convString(s,"@")="a@b@c"
static public String converString(String strToConv, String conv)


二、空值检测:
3、

Checks if a String is empty ("") or null.


判断一个字符串是否为空,空格作非空处理。 StringUtils.isEmpty(null) = true StringUtils.isEmpty("") = true StringUtils.isEmpty(" ") = false StringUtils.isEmpty("bob") = false StringUtils.isEmpty(" bob ") = false

NOTE: This method changed in Lang version 2.0.

It no longer trims the String.
That functionality is available in isBlank().


@param str the String to check, may be null
@return true if the String is empty or null
public static boolean isEmpty(String str)


三、非空处理:
4、
Checks if a String is not empty ("") and not null.


判断一个字符串是否非空,空格作非空处理. StringUtils.isNotEmpty(null) = false StringUtils.isNotEmpty("") = false StringUtils.isNotEmpty(" ") = true StringUtils.isNotEmpty("bob") = true StringUtils.isNotEmpty(" bob ") = true

@param str the String to check, may be null
@return true if the String is not empty and not null
public static boolean isNotEmpty(String str)

5、

Checks if a String is not empty (""), not null and not whitespace only.


判断一个字符串是否非空,空格作空处理. StringUtils.isNotBlank(null) = false StringUtils.isNotBlank("") = false StringUtils.isNotBlank(" ") = false StringUtils.isNotBlank("bob") = true StringUtils.isNotBlank(" bob ") = true

@param str the String to check, may be null
@return true if the String is
not empty and not null and not whitespace
@since 2.0
public static boolean isNotBlank(String str)


四、 空格处理
6、
Removes control characters (char <= 32) from both

ends of this String, handling null by returning
null.


The String is trimmed using {@link String#trim()}.

Trim removes start and end characters <= 32.
To strip whitespace use {@link //strip(String)}.


To trim your choice of characters, use the

{@link //strip(String, String)} methods.


格式化一个字符串中的空格,有非空判断处理; StringUtils.trim(null) = null StringUtils.trim("") = "" StringUtils.trim(" ") = "" StringUtils.trim("abc") = "abc" StringUtils.trim(" abc ") = "abc"

@param str the String to be trimmed, may be null
@return the trimmed string, null if null String input
public static String trim(String str)

7、


Removes control characters (char <= 32) from both

ends of this String returning null if the String is
empty ("") after the trim or if it is null.

The String is trimmed using {@link String#trim()}.

Trim removes start and end characters <= 32.
To strip whitespace use {@link /stripToNull(String)}.


格式化一个字符串中的空格,有非空判断处理,如果为空返回null; StringUtils.trimToNull(null) = null StringUtils.trimToNull("") = null StringUtils.trimToNull(" ") = null StringUtils.trimToNull("abc") = "abc" StringUtils.trimToNull(" abc ") = "abc"

@param str the String to be trimmed, may be null
@return the trimmed String,
null if only chars <= 32, empty or null String input
@since 2.0
public static String trimToNull(String str)

8、


Removes control characters (char <= 32) from both

ends of this String returning an empty String ("") if the String
is empty ("") after the trim or if it is null.

The String is trimmed using {@link String#trim()}.

Trim removes start and end characters <= 32.
To strip whitespace use {@link /stripToEmpty(String)}.


格式化一个字符串中的空格,有非空判断处理,如果为空返回""; StringUtils.trimToEmpty(null) = "" StringUtils.trimToEmpty("") = "" StringUtils.trimToEmpty(" ") = "" StringUtils.trimToEmpty("abc") = "abc" StringUtils.trimToEmpty(" abc ") = "abc"

@param str the String to be trimmed, may be null
@return the trimmed String, or an empty String if null input
@since 2.0
public static String trimToEmpty(String str)


五、 字符串比较:
9、
Compares two Strings, returning true if they are equal.


nulls are handled without exceptions. Two null

references are considered to be equal. The comparison is case sensitive.


判断两个字符串是否相等,有非空处理。 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

@param str1 the first String, may be null
@param str2 the second String, may be null
@return true if the Strings are equal, case sensitive, or
both null
@see java.lang.String#equals(Object)
public static boolean equals(String str1, String str2)


10、

Compares two Strings, returning true if they are equal ignoring

the case.


nulls are handled without exceptions. Two null

references are considered equal. Comparison is case insensitive.


判断两个字符串是否相等,有非空处理。忽略大小写 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

@param str1 the first String, may be null
@param str2 the second String, may be null
@return true if the Strings are equal, case insensitive, or
both null
@see java.lang.String#equalsIgnoreCase(String)
public static boolean equalsIgnoreCase(String str1, String str2)


六、 IndexOf 处理
11、


Finds the first index within a String, handling null.

This method uses {@link String#indexOf(String)}.


A null String will return -1.


返回要查找的字符串所在位置,有非空处理 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

@param str the String to check, may be null
@param searchStr the String to find, may be null
@return the first index of the search String,
-1 if no match or null string input
@since 2.0
public static int indexOf(String str, String searchStr)

12、

Finds the first index within a String, handling null.

This method uses {@link String#indexOf(String, int)}.


A null String will return -1.

A negative start position is treated as zero.
An empty ("") search String always matches.
A start position greater than the string length only matches
an empty search String.


返回要由指定位置开始查找的字符串所在位置,有非空处理 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

@param str the String to check, may be null
@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
@since 2.0
public static int indexOf(String str, String searchStr, int startPos)


七、 子字符串处理:
13、
Gets a substring from the specified String avoiding exceptions.


A negative start position can be used to start n

characters from the end of the String.


A null String will return null.

An empty ("") String will return "".


返回指定位置开始的字符串中的所有字符 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"

@param str the String to get the substring from, may be null
@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
public static String substring(String str, int start)

14、

Gets a substring from the specified String avoiding exceptions.


A negative start position can be used to start/end n

characters from the end of the String.


The returned substring starts with the character in the start

position and ends before the end position. All postion counting is
zero-based -- i.e., to start at the beginning of the string use
start = 0. Negative start and end positions can be used to
specify offsets relative to the end of the String.


If start is not strictly to the left of end, ""

is returned.


返回由开始位置到结束位置之间的子字符串 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"

@param str the String to get the substring from, may be null
@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
public static String substring(String str, int start, int end)


15、 SubStringAfter/SubStringBefore(前后子字符串处理:


Gets the substring before the first occurance of a separator.

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.


返回指定字符串之前的所有字符 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"

@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
@since 2.0
public static String substringBefore(String str, String separator)

16、

Gets the substring after the first occurance of a separator.

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.


返回指定字符串之后的所有字符 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"

@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 after the first occurance of the separator,
null if null String input
@since 2.0
public static String substringAfter(String str, String separator)

17、

Gets the substring before the last occurance of a separator.

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.


返回最后一个指定字符串之前的所有字符 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"

@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 last occurance of the separator,
null if null String input
@since 2.0
public static String substringBeforeLast(String str, String separator)

18、

Gets the substring after the last occurance of a separator.

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 empty string if
the input string is not null.


返回最后一个指定字符串之后的所有字符 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") = ""

@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 after the last occurance of the separator,
null if null String input
@since 2.0
public static String substringAfterLast(String str, String separator)


八、 Replacing(字符串替换)
19、
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
@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
@see #replace(String text, String repl, String with, int max)
public static String replace(String text, String repl, String with)

20、

Replaces a String with another String inside a larger String,

for the first max values of the search String.


A null reference passed to this method is a no-op.


以指定字符串最大替换原来字符串的的指定字符串 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"

@param text text to search and replace in, may be null
@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
public static String replace(String text, String repl, String with, int max)


九、 Case conversion(大小写转换)
21、

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"

@param str the String to upper case, may be null
@return the upper cased String, null if null String input
public static String upperCase(String str) 22、

Converts a String to lower case as per {@link String#toLowerCase()}.


A null input String returns null.


将一个字符串转换为小写 StringUtils.lowerCase(null) = null StringUtils.lowerCase("") = "" StringUtils.lowerCase("aBc") = "abc"

@param str the String to lower case, may be null
@return the lower cased String, null if null String input
public static String lowerCase(String str) 23、

Capitalizes a String changing the first letter to title case as

per {@link Character#toTitleCase(char)}. No other letters are changed.


For a word based alorithm, see {@link /WordUtils#capitalize(String)}.

A null input String returns null.


StringUtils.capitalize(null) = null StringUtils.capitalize("") = "" StringUtils.capitalize("cat") = "Cat" StringUtils.capitalize("cAt") = "CAt"

@param str the String to capitalize, may be null
@return the capitalized String, null if null String input
@see /WordUtils#capitalize(String)
@see /uncapitalize(String)
@since 2.0
将字符串中的首字母大写
public static String capitalize(String str)
分享到:
评论
2 楼 ahcr1026212 2014-08-07  
 
1 楼 Programmer2.x 2009-03-20  
楼主:StringUtil这个文件有吗?

能发一份给我吗?

QQ:105671304

Email:zjzhuomian@qq.com

相关推荐

    Java常用工具包Jodd.zip

    Jodd = Tools IoC MVC DB AOP TX JSON HTML < 1.5 MbJodd 被分成众多模块,按需选择,其中工具类模块有:jodd-core 一些工具类,包括Printf、JDateTime、StringUtil、Fast buffers等等jodd-bean BeanUtil以及类型...

    移动代理服务器MAS开发包和开发手册

    public final SmSendResultBean[] querySmsResult(int sm_id, java.util.Date fromTime,java.util.Date endTime,String orgAddr,String destAddr) throws Exception 查询短消息发送结果。 Int sendMultiSm...

    哈夫曼函数源代码MATLAB-Lossless_Compression_Toolkit_For_MATLAB:使用静态函数为MATLAB构建的

    哈夫曼函数源代码MATLAB 适用于MATLAB的无损数据压缩工具包 由Ethan Bovard,Nate Evarts和Neil Nguyen在2021年Spring学期完成的乔治亚州立大学的MATLAB课程。 该MATLAB构建的类工具包包括多个类,这些类通常用于...

    Java基础的时间函数以及遗漏

     java.util包提供了 一系列的常用的类,比如 Date,calendar类,  1.Date 类 是 用户可以 获取系统的时间,或者自己来设置,  Date date=new Date();  得到的 是当前的时间。  2.格式的转化问题,用到了...

    java期末复习第讲面向对象程序设计.pptx

    2023年5月29日 jdk中常用的包 java.lang----包含一些Java语言的核心类,如String、Math、Integer、System和Thread,提供常用功能。 java.awt----包含了构成抽象窗口工具集(abstract window toolkits)的多个类,...

    Jodd工具集-其他

    jodd-core 一些工具类,包括Printf、JDateTime、StringUtil、Fast buffers等等 jodd-bean BeanUtil以及类型检查转换工具 jodd-props 更强大的Java Properties替代 jodd-email 更简单易用的e-mail收发 jodd-upload ...

    计算器_j2se项目源码及介绍

    函数描述 public CalculateButton(Action listener,String text,int key,boolean isctrl) 构造一个具有缺省事件、指定文本、指定快捷键的JButton。 public CalculateButton(Action listener,String text,int key,...

    java源码包2

     util实现Java图片水印添加功能,有添加图片水印和文字水印,可以设置水印位置,透明度、设置对线段锯齿状边缘处理、水印图片的路径,水印一般格式是gif,png,这种图片可以设置透明度、水印旋转等,可以参考代码...

    用程序输出“当前时间是XXXX年XX月XX日XX时XX分XX秒(第XX周,周X)

    自学Date类(java.util.Date)和SimpleDateFormat类,用程序输出“当前时间是XXXX年XX月XX日XX时XX分XX秒(第XX周,周X)” 2 比较String与StringBuffer、StringBuilder的自增速度。方法:在自增前记录系统时间,...

    java源码包3

     util实现Java图片水印添加功能,有添加图片水印和文字水印,可以设置水印位置,透明度、设置对线段锯齿状边缘处理、水印图片的路径,水印一般格式是gif,png,这种图片可以设置透明度、水印旋转等,可以参考代码...

    java源码包4

     util实现Java图片水印添加功能,有添加图片水印和文字水印,可以设置水印位置,透明度、设置对线段锯齿状边缘处理、水印图片的路径,水印一般格式是gif,png,这种图片可以设置透明度、水印旋转等,可以参考代码...

    通用Android工具库Common4Android.zip

    StringUtil.java 字符串处理工具类。 SystemIntentUtil.java 系统Intent工具类,常用的系统Intent跳转函数,如:打电话、发短信等。 示例代码: - ...

    java源码包---java 源码 大量 实例

     util实现Java图片水印添加功能,有添加图片水印和文字水印,可以设置水印位置,透明度、设置对线段锯齿状边缘处理、水印图片的路径,水印一般格式是gif,png,这种图片可以设置透明度、水印旋转等,可以参考代码...

    上机实验-2 (1).doc

    import java.util.StringTokenizer; //导入 public class Test1 extends JFrame {//继承JFrame private final JPanel contentPane;//私有类,其他类不能享用 private final JTextPane numberField;//容器类 ...

    Guava 16.0 API (CHM格式)

    Guava 是一个 Google 的基于java1.6的类库集合的扩展项目,包括 collections, caching, primitives support, concurrency libraries, common annotations, string processing, I/O, 等等. 这些高质量的 API 可以使你...

    crypto-utils:Java 加密实用程序类

    依赖关系用于 Base64 编码/解码的 Apache 公共编解码器(包含在 lib 文件夹中)例子您可以检查 util 类中的main函数,但其​​要点是: final String text_to_encrypt = "This is the text to encrypt";final String...

    javaee三大框架整合宅急送项目lib包

    ProcessInstance的 java.util.Set<java.lang.String> findActiveActivityNames() @Override public List<ActivityCoordinates> findActivityCoordinates(String pid) { // 1、 根据流程实例id 获得所有活动...

    Java编程实现中英混合字符串数组按首字母排序的方法

    本文实例讲述了Java编程实现中英混合字符串数组按首字母排序的方法。分享给大家供大家参考,具体如下: 在Java中对于字符串数组的排序,我们可以使用Arrays.sort... com = Collator.getInstance(java.util.Locale

    java时间格式大全(算法源码)

    public static String dateToStrLong(java.util.Date dateDate) { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String dateString = formatter.format(dateDate); return date...

    JDT生成代码实例

    String[] imports = {"java.util.Date", "java.util.Random"}; for(String imp : imports){ //创建一个新包声名 ImportDeclaration importDeclaration = ast.newImportDeclaration(); //添加包说明 ...

Global site tag (gtag.js) - Google Analytics