简体   繁体   中英

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.

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

If this context contains any value from db, it should return true when i sysout it. Thanks in advance for your help.

I am using org.json.simple library

Just check if the context is null or not and return if size() is grater than 0 .

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

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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