![]() |
Commons-Lang のバックアップ(No.4) |
||
Jakarta Commons Langは、主にjava.lang パッケージを対象にした再利用性の高いユーティリティクラスを提供します。
null | "" | " " | "abc" | |
isEmpty | true | true | false | false |
isNotEmpty? | false | false | true | true |
isBlank | true | true | true | false |
isNotBlank? | false | false | false | true |
if (StringUtils.isEmpty(str)) { System.out.println(str.toUpperCase()); }
null, null | null, "abc" | "abc", null | "abc", "abc" | "abc", "ABC" | |
equals | true | false | false | true | false |
equalsIgnoreCase? | true | false | false | true | true |
null | "" | " " | "abc" | " abc " | |
trim | null | "" | "" | "abc" | "abc" |
trimToNull? | null | null | null | "abc" | "abc" |
trimToEmpty? | "" | "" | "" | "abc" | "abc" |
null | "" | " " | "abc" | " abc" | "abc " | " abc " | |
strip | null | "" | "" | "abc" | "abc" | "abc" | "abc" |
stripToNull? | null | null | null | "abc" | "abc" | "abc" | "abc" |
stripToEmpty? | "" | "" | "" | "abc" | "abc" | "abc" | "abc" |
StringUtils.split(null) -> null StringUtils.split(" abc def ") -> ["abc", "def"]
StringUtils.split("abc def", null) -> ["abc", "def"] StringUtils.split("ab:cd:ef", ":") -> ["ab", "cd", "ef"] StringUtils.split("ab::ef", ":") -> ["ab", "ef"]
StringUtils.join([null, "", "a", "bc"]) -> "abc"
StringUtils.join(["a", "b", "c"], null) -> "abc" StringUtils.join([null, "", "a", "bc"], ',') -> ",,a,bc"
各種に対応した文字列のエスケープ処理を
メソッド | 変換前 | 変換後 |
escapeJava | "ABC" | \"ABC\" |
escapeJavaScript? | "ABC" | \"ABC\" |
escapeHtml | A&B | A&B |
escapeXml | A&B | A&B |
escapeSql | ' | '' |
// 日単位で四捨五入する(時間は0) Calendar cal = DateUtils.round(Calendar.getInstance(), Calendar.DATE)
// 日単位で切り捨てる(時間は0) Calendar cal = DateUtils.truncate(Calendar.getInstance(), Calendar.DATE)
// 今週の日曜から始まる一週間のIteratorを取得する Iterator days = DateUtils.iterator(Calendar.getInstance(), DateUtils.RANGE_WEEK_SUNDAY)