導航:首頁 > 源碼編譯 > stringutils源碼

stringutils源碼

發布時間:2022-06-21 06:54:05

java.lang.NullPointerException 求幫忙解決,源碼附著如下

busiLogId 這個有可能為空。要具體看看CommonUtil.getBusiParam這個方法的返回值。

⑵ org.apache.commons.lang.StringUtils的jar包是什麼

commons-lang-2.5.jar
名字大概是這個,具體的版本是不是2.5要看你工程框架或JDK的版本,要試試才知道。

⑶ StringUtils.isNotEmpty(note.getName())的源碼有嗎或其具體使用

callNo.contains(" ")這個是判斷 callNo是否包含空格,你可以數一下到底包含了幾個空格。StringUtils.isNotEmpty(callNo)
僅能判斷 是否為null或者空字元串""。包含空格是判斷不了的。
比如 "123456"不符合條件,但是"123 456"卻是符合條件的!

⑷ StringUtils是哪個包下的類

org.apache.commons.lang.StringUtils中方法的操作對象是java.lang.String類型的對象,是JDK提供的String類型操作方法的補充,並且是null安全的(即如果輸入參數String為null則不會拋出NullPointerException,而是做了相應處理,例如,如果輸入為null則返回也是null等,具體可以查看源代碼)。
除了構造器,StringUtils中一共有130多個方法,並且都是static的,
所以我們可以這樣調用StringUtils.xxx()。
下面分別對一些常用方法做簡要介紹:
1. public static boolean isEmpty(String str)
判斷某字元串是否為空,為空的標準是str == null 或 str.length() == 0
下面是示例:
StringUtils.isEmpty(null) = true
StringUtils.isEmpty("") = true
StringUtils.isEmpty(" ") = false

⑸ org.springframework.util.stringutils 是java哪個jar包下的

spring-core




我們經常會對字元串進行操作,spring已經實現了常用的處理功能。我們可以使用org.springframework.util.StringUtils 工具類幫我們處理字元串。


工具類整理如下:


StringUtils.hasLength(null) = false
StringUtils.hasLength("") = false
StringUtils.hasLength(" ") = true
StringUtils.hasLength("Hello") = true
StringUtils.hasText(null) = false
StringUtils.hasText("") = false
StringUtils.hasText(" ") = false
StringUtils.hasText("12345") = true
StringUtils.hasText(" 12345 ") = true


//是否包含空白字元
StringUtils.containsWhitespace(null)=false
StringUtils.containsWhitespace("")=false
StringUtils.containsWhitespace("a")=false
StringUtils.containsWhitespace("abc")=false
StringUtils.containsWhitespace("abc")=false
StringUtils.containsWhitespace(" ")=true
StringUtils.containsWhitespace(" a")=true
StringUtils.containsWhitespace("abc ")=true
StringUtils.containsWhitespace("a b")=true
StringUtils.containsWhitespace("a b")

StringUtils.trimWhitespace(null)=null;
StringUtils.trimWhitespace("")="";
StringUtils.trimWhitespace(" ")="";
StringUtils.trimWhitespace("/t")="";
StringUtils.trimWhitespace(" a")="a";
StringUtils.trimWhitespace("a ")="a";
StringUtils.trimWhitespace(" a ")="a";
StringUtils.trimWhitespace(" a b ")="a b";

StringUtils.trimLeadingWhitespace(null)=null;
StringUtils.trimLeadingWhitespace("")="";
StringUtils.trimLeadingWhitespace(" ")="";
StringUtils.trimLeadingWhitespace("/t")="";
StringUtils.trimLeadingWhitespace(" a")="a";
StringUtils.trimLeadingWhitespace("a ")="a ";
StringUtils.trimLeadingWhitespace(" a ")="a ";
StringUtils.trimLeadingWhitespace(" a b ")="a b "
StringUtils.trimLeadingWhitespace(" a b c ")="a b c "

StringUtils.trimTrailingWhitespace(null)=null;
StringUtils.trimTrailingWhitespace(" ")="";
StringUtils.trimTrailingWhitespace("/t")="";
StringUtils.trimTrailingWhitespace("a ")="a";
StringUtils.trimTrailingWhitespace(" a")=" a";
StringUtils.trimTrailingWhitespace(" a ")=" a";
StringUtils.trimTrailingWhitespace(" a b ")=" a b";
StringUtils.trimTrailingWhitespace(" a b c ")=" a b c";

StringUtils.trimAllWhitespace("")="";
StringUtils.trimAllWhitespace(" ")="";
StringUtils.trimAllWhitespace("/t")="";
StringUtils.trimAllWhitespace(" a")="a";
StringUtils.trimAllWhitespace("a ")="a";
StringUtils.trimAllWhitespace(" a ")="a";
StringUtils.trimAllWhitespace(" a b ")="ab";
StringUtils.trimAllWhitespace(" a b c "="abc";


//統計一個子字元串在字元串出現的次數
StringUtils.countOccurrencesOf(null, null) == 0;
StringUtils.countOccurrencesOf("s", null) == 0;
StringUtils.countOccurrencesOf(null, "s") == 0;
StringUtils.countOccurrencesOf("erowoiueoiur", "WERWER") == 0;
StringUtils.countOccurrencesOf("erowoiueoiur", "x")=0;
StringUtils.countOccurrencesOf("erowoiueoiur", " ") == 0;
StringUtils.countOccurrencesOf("erowoiueoiur", "") == 0;
StringUtils.countOccurrencesOf("erowoiueoiur", "e") == 2;
StringUtils.countOccurrencesOf("erowoiueoiur", "oi") == 2;
StringUtils.countOccurrencesOf("erowoiueoiur", "oiu") == 2;
StringUtils.countOccurrencesOf("erowoiueoiur", "oiur") == 1;
StringUtils.countOccurrencesOf("erowoiueoiur", "r") == 2;



//字元串替換
String inString = "a6AazAaa77abaa";
String oldPattern = "aa";
String newPattern = "foo";


// Simple replace
String s = StringUtils.replace(inString, oldPattern, newPattern);
s.equals("a6AazAfoo77abfoo")=true;

// Non match: no change
s = StringUtils.replace(inString, "qwoeiruqopwieurpoqwieur", newPattern);
s.equals(inString)=true
s = StringUtils.replace(inString, oldPattern, null);
s.equals(inString)=true

// Null old pattern: should ignore
s = StringUtils.replace(inString, null, newPattern);
s.equals(inString)=true



//刪除字元串

String inString = "The quick brown fox jumped over the lazy dog";
String noThe = StringUtils.delete(inString, "the");
noThe.equals("The quick brown fox jumped over lazy dog")=true;
String nohe = StringUtils.delete(inString, "he");
nohe.equals("T quick brown fox jumped over t lazy dog")=true;
String nosp = StringUtils.delete(inString, " ");
nosp.equals("")=true;
String killEnd = StringUtils.delete(inString, "dog");
killEnd.equals("The quick brown fox jumped over the lazy ")=true;
String mismatch = StringUtils.delete(inString, "dxxcxcxog");
mismatch.equals(inString)=true;



//刪除任何字元
//源代碼如下

//char c = inString.charAt(i);
//如果不存在 c 值,則返回 -1
//if (charsToDelete.indexOf(c) == -1) {
//out.append(c);
//}

String inString = "Able was I ere I saw Elba";

String res = StringUtils.deleteAny(inString, "I");
res.equals("Able was ere saw Elba")=true;
res = StringUtils.deleteAny(inString, "AeEba!");
res.equals("l ws I r I sw l")=true;
String mismatch = StringUtils.deleteAny(inString, "#@$#$^");
mismatch.equals(inString)=true;

//源代碼如下 return (str != null ? "'" + str + "'" : null);
assertEquals("'myString'", StringUtils.quote("myString"));
assertEquals("''", StringUtils.quote(""));
assertNull(StringUtils.quote(null));


//將第一個字元改大寫
StringUtils.capitalize(Str)
//將第一個個字元改小寫
StringUtils.uncapitalize(str)


//mypath/myfile.txt" -> "myfile.txt
//獲取字元串文件名和擴展名

StringUtils.getFilename("myfile").equals("myfile")=true;
StringUtils.getFilename("mypath/myfile".equals("myfile")=true;
StringUtils.getFilename("mypath/myfile".equals("myfile")=true;
StringUtils.getFilename("myfile.txt").equals("myfile.txt")=true;
StringUtils.getFilename("mypath/myfile.txt").equals("myfile.txt")=true;



//獲取字元串擴展名,以.分隔
StringUtils.getFilenameExtension("myfile")=null;
StringUtils.getFilenameExtension("myPath/myfile")=null;
StringUtils.getFilenameExtension("myfile.").equals("")=true;
StringUtils.getFilenameExtension("myPath/myfile.").equals("")=true;
StringUtils.StringUtils.getFilenameExtension("myfile.txt").equals("txt")=true;
StringUtils.getFilenameExtension("mypath/myfile.txt").equals("txt")=true;


//捨去文件名擴展名
StringUtils.stripFilenameExtension(null)=true;
StringUtils.stripFilenameExtension("").equals("")=true;
StringUtils.stripFilenameExtension("myfile").equals("myfile")=true;
StringUtils.stripFilenameExtension("mypath/myfile").equals("mypath/myfile")=true;
StringUtils.stripFilenameExtension("myfile.").equals("myfile")=true;
StringUtils.stripFilenameExtension("mypath/myfile.").equals("mypath/myfile")=true;
StringUtils.stripFilenameExtension("mypath/myfile.").equals("mypath/myfile")=true;
StringUtils.stripFilenameExtension("myfile.txt").equals("myfile")=true;
StringUtils.stripFilenameExtension("mypath/myfile.txt").equals("mypath/myfile")=true;

⑹ 怎麼解決randomstringutils生成數字亂碼

源碼:
public static String random(int count, boolean letters, boolean numbers) {
return random(count, 0, 0, letters, numbers);
}
那麼20位的數字亂碼可以使用下面來生成:
random(20, false, true)

⑺ myeclipse怎麼看stringutils源碼

1、如果沒有附加源碼的話,是看不到源碼的,必須附加源碼:右鍵項目-Build Path-Configure Build Path-Java Build Path-Libraries-選擇jar包-點左邊的+號-選擇Source attatch-Edit-Browse-選擇源碼包就可以附加源碼了。
2、附加源碼後,要查看某個類/方法/變數的源碼,只要選中類/方法名/變數名,然後按F3即可看到源碼。

⑻ StringUtils中isEmpty 和isBlank的區別

1、空格參數

isEmpty沒有忽略空格參數,是以是否為空和是否存在為判斷依據。而isBlank忽略了空格參數。

2、層次

isBlank 是在isEmpty的基礎上進行了為空(字元串都為空格、製表符、tab 的情況)的判斷。因此isBlank層次更高。

3、使用頻率

isBlank的使用頻率更高,而isEmpty的使用頻率更高。

(8)stringutils源碼擴展閱讀

源代碼

isEmpty()

public static boolean isEmpty(String str) {

return str == null || str.length() == 0;

}

isBlank()

public static boolean isBlank(String str) {int strLen;

if (str != null && (strLen = str.length()) != 0) {for(int i = 0; i < strLen; ++i) {

// 判斷字元是否為空格、製表符、tab

if (!Character.isWhitespace(str.charAt(i))) {return false;}}

return true;

} else {return true;}}

閱讀全文

與stringutils源碼相關的資料

熱點內容
如何開放遠程伺服器上的埠號 瀏覽:67
大規模單片機廠家供應 瀏覽:952
3dmax編輯樣條線快捷命令 瀏覽:708
怎麼獲得音樂的源碼 瀏覽:249
郭麒麟參加密室完整版 瀏覽:318
單片機排線怎麼用 瀏覽:483
java字元串太長 瀏覽:868
python變數計算 瀏覽:115
網銀pdf 瀏覽:134
iponedns伺服器怎麼設置復原 瀏覽:405
深圳電力巡檢自主導航演算法 瀏覽:436
十二星座的布娃娃怎麼買app 瀏覽:321
反編譯打包地圖不顯示 瀏覽:92
沒有壓縮的圖片格式 瀏覽:468
斯維爾文件需不需要加密狗 瀏覽:300
柱加密區范圍在軟體中設置 瀏覽:706
紙質音樂壓縮教程 瀏覽:33
安卓手機健康碼快捷方式怎麼設置 瀏覽:477
程序員是怎麼發明的 瀏覽:175
新手程序員的職業規劃 瀏覽:175