Corey, I understand the constructors. But where do we use the second one? We use both true and false for boolean. But why do we need string? A tiny exmaple is appreciated.
Joined: Dec 20, 2001
Any time you have a String that contains a boolean literal, you may want to use this approach. Perhaps you're taking some input from a user and you know that the input will be either "true" or "false". You'll want to turn that input (which is a String) into a boolean, so you'll have to use the String constructor. Here's an example:
Granted, I doubt this would be used vary often. However, if you were to create an expert system, this may be a useful technique. Of course, Java isn't usually the language of choice for such a system, but the example just popped to mind. I hope that helps, Corey
very nice example Also, remember that the java.lang.Boolean(String) contructor gives some leeway -- it's case INsensitive. So Boolean("tRuE") and Boolean("true") both evaluate to Boolean.TRUE [ June 03, 2002: Message edited by: Jessica Sant ]