简体   繁体   English

在Java中检查NULL

[英]Checking for NULL in Java

I am using a Bonded JComboBox. 我正在使用Bonded JComboBox。 What I want to know is how do I check if that JComboBox has any items in it or not. 我想知道的是如何检查JComboBox是否包含任何项目。

Thank you. 谢谢。

To test if the JComboxBox reference is null , you can compare it with null using the == operator. 要测试JComboxBox引用是否为null ,可以使用==运算符将其与null进行比较。 To test if the combo-box contains any items, you can use the instance method getItemCount , which returns the number of items it contains. 要测试组合框是否包含任何项目,可以使用实例方法getItemCount ,该方法返回其包含的项目数。

JComboxBox box = ...
boolean boxIsNull = (box == null); // answers the title of the question
boolean boxHasItems = (box.getItemCount() > 0);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM