I cant believe how much time ive spent trying to use Java's Booleans. In my opinion, C++ was much simpler here. First, what is the difference, if any, between a Boolean and a boolean? Can i even declare (or construct) or A boolean? What i would like to do is use a test function that test a condition or two and then returns a Boolean(or is it boolean?) indicating whether the test condition was true or false. Here's what I've tried so far. private Boolean test(some arguments) { if(condition) return new Boolean("True"); //Ive also tried return TRUE and return FALSE else return new Boolean("False"); //Ive tried return new Boolean(1) and return new Boolean(0) } When this functions returns its value I would like to use it in an IF statement. It seems that Java only accepts Booleans (or booleans?) expressions in an IF test conditon. Do I really need booleans? If i do, whats the correct way to use them here?
Marilyn de Queiroz
Sheriff
Joined: Jul 22, 2000
Posts: 9033
10
posted
0
First, what is the difference, if any, between a Boolean and a boolean? Can i even declare (or construct) or A boolean?
A boolean is a primitive that can be initialized to "true" or "false" (without the quote marks). A Boolean is a wrapper object used when you have a boolean and need an object. The two are not the same.
JavaBeginnersFaq "Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Marilyn de Queiroz
Sheriff
Joined: Jul 22, 2000
Posts: 9033
10
posted
0
Here's what I've tried so far. private Boolean test(some arguments) { if(condition) return new Boolean("True"); //Ive also tried return TRUE and return FALSE else return new Boolean("False"); //Ive tried return new Boolean(1) and return new Boolean(0) }
When this functions returns its value I would like to use it in an IF statement. It seems that Java only accepts Booleans (or booleans?) expressions in an IF test conditon.
Do I really need booleans? If i do, whats the correct way to use them here?
Definitely better, Junilu. I was trying to stick fairly close to the code he gave so he could see the changes, but I would definitely use yours in real life.