Skip to content

Commit

Permalink
Merge pull request #2816 from 847689421/v5-dev
Browse files Browse the repository at this point in the history
BooleanUtil增加toString(Boolean bool, String trueString, String falseString, String nullString)方法
  • Loading branch information
looly authored Dec 27, 2022
2 parents f9dbb4c + d63d281 commit 0cf4a8d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions hutool-core/src/main/java/cn/hutool/core/util/BooleanUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,28 @@ public static String toString(boolean bool, String trueString, String falseStrin
return bool ? trueString : falseString;
}

/**
* 将boolean转换为字符串
*
* <pre>
* BooleanUtil.toString(true, "true", "false", null) = "true"
* BooleanUtil.toString(false, "true", "false", null) = "false"
* BooleanUtil.toString(null, "true", "false", null) = null
* </pre>
*
* @param bool Boolean值
* @param trueString 当值为 {@code true}时返回此字符串, 可能为 {@code null}
* @param falseString 当值为 {@code false}时返回此字符串, 可能为 {@code null}
* @param nullString 当值为 {@code null}时返回此字符串, 可能为 {@code null}
* @return 结果值
*/
public static String toString(Boolean bool, String trueString, String falseString, String nullString) {
if (bool == null) {
return nullString;
}
return bool ? trueString : falseString;
}

/**
* 对Boolean数组取与
*
Expand Down

0 comments on commit 0cf4a8d

Please sign in to comment.