Differences among various bool types?

Viewed 51640

What are the differences among bool, boolean and Boolean in Java/Android?

3 Answers

boolean is a primitive boolean type and occupies less memory. Boolean is the wrapper object for a boolean which introduced in JDK 1.5.

  1. Suppose you have a service API which will execute a query and get the data from multiple tables.
  2. After that this data is to be manipulated and converted into the json object.
  3. During this conversion, it ight be possible that some boolean field may have 'NULL' as value.
  4. While receiving it as a response, you will definately parse it into an object.
  5. This automatic conversion may fail if your conversion logic will try to parse Boolean 'NULL' value into boolean primitive variable because boolean can't accept 'NULL' values.
Related