简体   繁体   English

在Java中检查布尔值

[英]Check Boolean value in Java

I want to return a boolean value to check if the String contains any 'value' or not after getting data from database. 我想返回一个布尔值,以检查从数据库中获取数据后字符串是否包含任何“值”。 It should return true if it contains anything else false. 如果它包含其他任何false,则应返回true。

JSONObject context = memory.getContext(senderId, sessionId);

If this context contains any value from db, it should return true when i sysout it. 如果此上下文包含db中的任何值,则在我sysout时应返回true。 Thanks in advance for your help. 在此先感谢您的帮助。

I am using org.json.simple library 我正在使用org.json.simple库

Just check if the context is null or not and return if size() is grater than 0 . 只需检查上下文是否为null ,然后返回size()是否大于0

...
JSONObject context = memory.getContext(senderId, sessionId);

return context != null && context.size() > 0;

由于JSONObjectorg.json.simple.JSONObject它的size方法将使您确定它是否具有任何内容,例如:

return context != null && context.size() > 0;

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

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