Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Feb 2007
    Posts
    83
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Question How to convert string to boolean

    If i want to convert string value in boolean then how can i do this?
    For example : am passing arguments "true" or "false" into the parameter.According to the value (true/false) user entered, it should show me 0 /1.


    Thanks ,

  2. #2
    Regular Coder
    Join Date
    Oct 2006
    Location
    United Kingdom
    Posts
    866
    Thanks
    7
    Thanked 30 Times in 29 Posts
    here is an example of converting from strings to boolean values

    Code:
    String val = "true";
    boolean ok = Boolean.parseBoolean(val) ;
    Cheers,
    Ess

  3. #3
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    pls note parseBoolean is available only in java5 for prev versions u have to go through this
    Code:
    boolean ok = Boolean.valueOf(val).booleanValue();
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  4. #4
    New Coder
    Join Date
    Feb 2007
    Posts
    83
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Thanks


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •