Skip to content
Advertisement

If else condition with StringBuffer

I’m trying to make a If else condition to check if a current data exists on the database using a JSON request on a java application consuming a Rest Webservice.

So, I want to receive a boolean or make a condition to verify what i’m receiving (normally, null or true/false)

There’s a way to transform this in a boolean to make the condition:

JavaScript

or how can I receive a StringBuffer and compare in this If-Else?

Here’s the code of how I’m receiving the StringBuffer:

JavaScript

and here’s how i’m trying to make the condition:

JavaScript

Advertisement

Answer

A StringBuffer (or String) will never equal a boolean. But it could equal "true". Also you should prefer StringBuilder to StringBuffer. Assuming you have response as a StringBuilder (or a StringBuffer) you could do

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement