Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2006

Tip: Looking for answers? Try searching our database.

boolean values into a string

Thread view: 
NAJH - 23 Jul 2006 15:43 GMT
I'm a newbie to Java so be patient with my simplistic questions... :o)

I have a boolean result from something and I want to put it into a
property value, against a given key. Not sure how to do this though.

// background on why I want to do this:
The boolean result is from using a roots[].canWrite() for a particular
file. I want to populate a property object with a load of these
canWrite() results corresponding to different root directories.

Many thanks!
NAJH - 23 Jul 2006 16:32 GMT
> I'm a newbie to Java so be patient with my simplistic questions... :o)
>
> I have a boolean result from something and I want to put it into a
> property value, against a given key. Not sure how to do this though.

I've ended up using an if statement to check whether the boolean is
true or false and then writing a temporary string with the value "true"
or "false", which is then used in the Properties class

I feel there must be a better way though.
Lee Weiner - 23 Jul 2006 16:58 GMT
>> I'm a newbie to Java so be patient with my simplistic questions... :o)
>>
[quoted text clipped - 6 lines]
>
>I feel there must be a better way though.

There are other ways. "Better" is subjective, however.

String str = Boolean.toString( boolenvalue);

Lee Weiner
lee AT leeweiner DOT org
jtl.zheng - 23 Jul 2006 17:30 GMT
one more way:
public static String String.valueOf(boolean b)
Patricia Shanahan - 23 Jul 2006 17:45 GMT
> I'm a newbie to Java so be patient with my simplistic questions... :o)
>
[quoted text clipped - 7 lines]
>
> Many thanks!

I agree with the previously posted responses pointing out Java API
methods to do what you want. Also, java.io.PrintStream.printf() has a %b
format specifier.

However, I have a more general comment about your questions. I get the
impression that you have programmed previously, but not in Java, and you
are trying to program by applying techniques from other languages.

In some cases, you can tell there must be a better way, and ask about it
here. There will be other cases in which there is a better way, but the
way you are using works just well enough to keep you from asking about it.

If you have not already done so, I strongly recommend getting a book on
Java and reading it in parallel with practicing coding in Java.

Patricia
NAJH - 24 Jul 2006 00:05 GMT
<snip>
> However, I have a more general comment about your questions. I get the
> impression that you have programmed previously, but not in Java, and you
[quoted text clipped - 8 lines]
>
> Patricia

Thanks for all your comments everyone.

Hi Patricia,
Yep, you're quite right. I've 'programmed' in other languages. (In
quotes because I don't think I'm terribly good.) I've dabbled with
BASIC, VB in *all* its variations (even the Australian variety),
JavaScript, touched on C and C++ at uni, done a little ActionScript
(that's the stuff Adobe Flash uses), loads of SQL, even some UML and
OCL (why does OCL exist?)... I've not really got firmly to grips with
an OO language though.

To be honest I'm doing a course in Java in my spare time and so have
several books of various sorts. But sometimes it's a little difficult
to get into the real grime of what's going on without playing around
with stuff. Examples in books are fine, but they don't engage the brain
much do they?

The nicest reference book I have so far is one of the O'Reilly ones.
Java in a Nutshell I think. I grabbed it from the library. Do you have
any recommendations? I'm not really after a "course" type book but a
damn good reference I guess...

All the best,
Neil
Patricia Shanahan - 24 Jul 2006 01:44 GMT
> <snip>
>> However, I have a more general comment about your questions. I get the
[quoted text clipped - 31 lines]
> any recommendations? I'm not really after a "course" type book but a
> damn good reference I guess...

As long as you are doing a course in Java you should be OK. That will
make sure you learn about arrays, collections etc.

For an API reference, I strongly recommend
http://java.sun.com/j2se/1.5.0/docs/api/index.html. I keep a downloaded
copy on each computer where I do Java development.

Generally, the best way I've found to learn programming languages is to
alternate reading with attempts at programming in the language, which is
what you seem to be doing.

Good luck,

Patricia


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.