如何检查两个布尔值是否相等?

编程入门 行业动态 更新时间:2024-10-27 02:19:32
本文介绍了如何检查两个布尔值是否相等?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要一个方法,我可以在junit assertTrue()方法中调用它来比较两个布尔值以检查它们是否相等,返回一个布尔值。例如,类似这样的事情:

I need a method which I can call within the junit assertTrue() method which compares two booleans to check if they are equal, returning a boolean value. For example, something like this:

boolean isEqual = Boolean.equals(bool1, bool2);

如果不相等则返回false,如果相等则返回true。我已经检查了布尔类,但唯一接近的是 Booleanpare(),它返回一个我无法使用的int值。

which should return false if they are not equal, or true if they are. I've checked out the Boolean class but the only one that comes close is Booleanpare() which returns an int value, which I can't use.

推荐答案

== 运算符适用于布尔值。

The == operator works with booleans.

boolean isEqual = (bool1 == bool2);

(括号是不必要的,但有助于简化阅读。)

(The parentheses are unnecessary, but help make it easier to read.)

更多推荐

如何检查两个布尔值是否相等?

本文发布于:2023-11-08 13:24:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1569488.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:两个   布尔值

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!