【发布时间】:2020-06-02 06:40:30
【问题描述】:
如何确定字符串的输入是“真”还是“假”,然后将其解析为布尔值?
例如:
String input = "true"; -> boolean result = true;
String input = "false"; -> boolean result = false;
String input = "foobar"; -> throw new InvalidInputException("true or false is allowed");
【问题讨论】:
-
用
if声明检查它? -
你的意思是:equals 或 equalsIgnoreCase 是如何工作的?
标签: java string type-conversion boolean