This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

does this make sense?

 
Mellihoney Michael
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Boolean b=new Boolean("abcd");
[ February 15, 2003: Message edited by: Mellihoney Michael ]
 
Piotr Kaluski
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it does.
There is a constructor for Boolean which takes a literal. If the literal is "True" (case does not matter), the object wraps true. If it is something else (like "abcd") the object will wrap "false".
 
Sarma Lolla
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi the following are from JAVA API on Boolean class for valueOf methods.
My question is when we send a string as parameter to Boolean.ValueOf method is the return value is one of Boolean.TRUE / Boolean.FALSE? If so like in ValueOF(boolean) why doesn't API specify the same?


public static Boolean valueOf(boolean b)Returns a Boolean instance representing the specified boolean value. If the specified boolean value is true, this method returns Boolean.TRUE; if it is false, this method returns Boolean.FALSE. If a new Boolean instance is not required, this method should generally be used in preference to the constructor Boolean(boolean), as this method is likely to to yield significantly better space and time performance.
Parameters


public static Boolean valueOf(String s)Returns a Boolean with a value represented by the specified String. The Boolean returned represents the value true if the string argument is not null and is equal, ignoring case, to the string "true".

[ February 13, 2003: Message edited by: Sarma Lolla ]
[ February 13, 2003: Message edited by: Sarma Lolla ]
[ February 13, 2003: Message edited by: Sarma Lolla ]
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is often a nice and interesting expedition to go see the JDK source code. In this case, we have to look at the class java.lang.Boolean. Below is the constructor Boolean(String) constructor as well as one of the private toBoolean() method invoked within the body of the constructor.

Form the code we case see, as Piotr mentioned, that if the value of the given String object is "true" (whatever the case) then the Boolean object will wrap a true else a false.
Remember: the answer is out there
[ February 13, 2003: Message edited by: Valentin Crettaz ]
 
Piotr Kaluski
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Were can I find the source code for JDK?
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the src.zip file bundled with the J2SE release.
Otherwise you can go there:
http://wwws.sun.com/software/java2/download.html
[ February 14, 2003: Message edited by: Valentin Crettaz ]
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic