Java Boolean example to check whether the given string is Boolean or not using parseBoolean


public static boolean parseBoolean(String s)
    Parses the string argument as a boolean. The boolean returned represents the     value true if the string argument is not null and is equal, ignoring case, to the     string "true".
    Example: Boolean.parseBoolean("True") returns true.
    Example: Boolean.parseBoolean("yes") returns false.


Program:

package com.candidjava;
import java.lang.*;

public class BooleanParseBoolean
{
public static void main(String[] args)
{
// create and assign values to String's s1, s2
String s1 = "TRue";
String s2 = "yes";

boolean bool1, bool2;
bool1 = Boolean.parseBoolean(s1);
bool2 = Boolean.parseBoolean(s2);

String str1 = "Parse boolean on " + s1 + " gives " + bool1;
String str2 = "Parse boolean on " + s2 + " gives " + bool2;

System.out.println( str1 );
System.out.println( str2 );
}
}


Output:

Parse boolean on TRue gives true
Parse boolean on yes gives false


Description:

This method returns the boolean represented by the string argument.


Parameters:
    
s - the String containing the boolean representation to be parsed


Returns:
    
the boolean represented by the string argument




Related Post

Comments


©candidjava.com