1. 程式人生 > >commons.lang中常用的工具類

commons.lang中常用的工具類


//縮短到某長度,用...結尾.其實就是(substring(str, 0, max-3) + "...")         
//public static String abbreviate(String str,int maxWidth)          StringUtils.abbreviate( "abcdefg" 6
); // ---"abc..."                     //字串結尾的字尾是否與你要結尾的字尾匹配,若不匹配則新增字尾
         StringUtils.appendIfMissing( "abc" , "xyz" ); //---"abcxyz"          StringUtils.appendIfMissingIgnoreCase( "abcXYZ" , "xyz" ); //---"abcXYZ"                     //首字母大小寫轉換          StringUtils.capitalize( "cat" ); //---"Cat"          StringUtils.uncapitalize( "Cat" ); //---"cat"                     //字串擴充至指定大小且居中(若擴充大小少於原字元大小則返回原字元,若擴充大小為 負數則為0計算 )          StringUtils.center( "abcd" 2 ); //--- "abcd"          StringUtils.center( "ab" , - 1 ); //--- "ab"          StringUtils.center( "ab" 4 ); //---" ab "          StringUtils.center( "a" 4 "yz" ); //---"yayz"          StringUtils.center( "abc" 7 "" ); //---"  abc  "                     //去除字串中的"\n", "\r", or "\r\n"          StringUtils.chomp( "abc\r\n" ); //---"abc"                     //判斷一字串是否包含另一字串          StringUtils.contains( "abc" "z" ); //---false          StringUtils.containsIgnoreCase( "abc" "A" ); //---true                     //統計一字串在另一字串中出現次數          StringUtils.countMatches( "abba" "a" ); //---2                     //刪除字串中的梭有空格          StringUtils.deleteWhitespace( "   ab  c  " ); //---"abc"                     //比較兩字串,返回不同之處。確切的說是返回第二個引數中與第一個引數所不同的字串          StringUtils.difference( "abcde" "abxyz" ); //---"xyz"                     //檢查字串結尾字尾是否匹配          StringUtils.endsWith( "abcdef" "def" ); //---true          StringUtils.endsWithIgnoreCase( "ABCDEF" "def" ); //---true          StringUtils.endsWithAny( "abcxyz" new  String[] { null "xyz" "abc" }); //---true                     //檢查起始字串是否匹配          StringUtils.startsWith( "abcdef" "abc" ); //---true          StringUtils.startsWithIgnoreCase( "ABCDEF" "abc" ); //---true          StringUtils.startsWithAny( "abcxyz" new  String[] { null "xyz" "abc" }); //---true                     //判斷兩字串是否相同          StringUtils.equals( "abc" "abc" ); //---true          StringUtils.equalsIgnoreCase( "abc" "ABC" ); //---true                     //比較字串陣列內的所有元素的字元序列,起始一致則返回一致的字串,若無則返回""          StringUtils.getCommonPrefix( new  String[] { "abcde"