New Tutorials:   JAVASCRIPT    SASS/SCSS    PL/SQL  
See the Tutorial List

Boolean class


Below are the Methods of Boolean class and their example.

1. static boolean parseBoolean(String s)

Syntax :

	
public static boolean parseBoolean(String s)
	

Example:

	
public class booleanDemo1
{ 
    public static void main(String[] args) 
    { 
        boolean obj1 = Boolean.parseBoolean("True"); 
	boolean obj2 = Boolean.parseBoolean("False");
        boolean obj3 = Boolean.parseBoolean("StUdYtONiGhT"); 
        boolean obj4 = Boolean.parseBoolean("STUDYTONIGHT"); 
        boolean obj5 = Boolean.parseBoolean("studytonight"); 
        System.out.println(obj1); 
        System.out.println(obj2); 
        System.out.println(obj3); 
        System.out.println(obj4); 
        System.out.println(obj5);   
    } 
}
	

boolean-class-example


2. boolean booleanValue()

Syntax:

	
public boolean booleanValue()
	

Example:

	
public class booleanDemo1
{ 
    public static void main(String[] args) 
    { 
        Boolean obj1 = new Boolean("True"); 
        Boolean obj2 = new Boolean("StUdYtONiGhT"); 
        Boolean obj3 = new Boolean("STUDYTONIGHT"); 
        Boolean obj4 = new Boolean("studytonight"); 

	boolean obj5 = obj1.booleanValue();
	boolean obj6 = obj2.booleanValue();
	boolean obj7 = obj3.booleanValue();
	boolean obj8 = obj4.booleanValue();

        System.out.println(obj5); 
        System.out.println(obj6); 
        System.out.println(obj7); 
        System.out.println(obj8);   
    } 
}
	

boolean-class-example-1.JPG


3. static Boolean valueOf(boolean b)

Syntax:

	
public static boolean valueOf(boolean b)
	

Example:

	
public class booleanDemo1
{ 
    public static void main(String[] args) 
    { 
	boolean obj1 = true;
	boolean obj2 = false;
	
	Boolean obj3 = Boolean.valueOf(obj1);
	Boolean obj4 = Boolean.valueOf(obj2);

        System.out.println(obj3); 
        System.out.println(obj4);    
    } 
}
	

boolean-class-example


4. static Boolean valueOf(String s)

Syntax:

	
public static boolean valueOf(String s)
	

Example:

	
public class booleanDemo1
{ 
    public static void main(String[] args) 
    { 
Boolean obj1 = Boolean.valueOf("True"); 
Boolean obj2 = Boolean.valueOf(null);
        Boolean obj3 = Boolean.valueOf("StUdYtONiGhT"); 
        Boolean obj4 = Boolean.valueOf("STUDYTONIGHT"); 
        Boolean obj5 = Boolean.valueOf("studytonight"); 
        System.out.println(obj1); 
        System.out.println(obj2); 
        System.out.println(obj3); 
        System.out.println(obj4); 
        System.out.println(obj5);   
    } 
}
	

boolean-class-example-3.JPG


5. static String toString(boolean b)

Syntax:

	
public static String toString(boolean b)
	

Example:

	
public class booleanDemo1
{ 
    public static void main(String[] args) 
    { 
boolean obj1 = true; 
        boolean obj2 = false; 

        String s1 = Boolean.toString(obj1); 
        String s2 = Boolean.toString(obj2); 

        System.out.println(s1); 
        System.out.println(s2);
    } 
}
	

boolean-class-example


6. String toString()

Syntax:

	
public String toString()
	

Example:

	
public class booleanDemo1
{ 
    public static void main(String[] args) 
    { 
        Boolean obj1 = new Boolean("True"); 
        Boolean obj2 = new Boolean(null);
        Boolean obj3 = new Boolean("StUdYtONiGhT"); 
        Boolean obj4 = new Boolean("STUDYTONIGHT"); 
        Boolean obj5 = new Boolean("studytonight"); 
	
	String s1 = obj1.toString();
	String s2 = obj2.toString();
	String s3 = obj3.toString();
	String s4 = obj4.toString();
	String s5 = obj5.toString();

		System.out.println(s1); 
        System.out.println(s2); 
        System.out.println(s3); 
        System.out.println(s4); 
        System.out.println(s5); 
    } 
}
	

boolean-class-example


7. int hashCode()

Syntax:

	
public int hashCode()
	

Example:

	
public class booleanDemo1
{ 
    public static void main(String[] args) 
    { 
        Boolean obj1 = new Boolean("True"); 
        Boolean obj2 = new Boolean(null);
        Boolean obj3 = new Boolean("StUdYtONiGhT"); 
        Boolean obj4 = new Boolean("STUDYTONIGHT"); 
        Boolean obj5 = new Boolean("studytonight"); 

		System.out.println(obj1.hashCode()); 
        System.out.println(obj2.hashCode()); 
        System.out.println(obj3.hashCode()); 
        System.out.println(obj4.hashCode()); 
        System.out.println(obj5.hashCode()); 
    } 
}
	

boolean-class-example


8. boolean equals(Object obj)

Syntax:

	
8. boolean equals(Object obj)
	

Example:

	
public class booleanDemo1
{ 
    public static void main(String[] args) 
    { 
        Boolean obj1 = new Boolean("True"); 
        Boolean obj2 = new Boolean(null);
        Boolean obj3 = new Boolean("StUdYtONiGhT"); 
        Boolean obj4 = new Boolean("STUDYTONIGHT"); 
        Boolean obj5 = new Boolean("studytonight"); 

		System.out.println(obj1.equals(obj2)); 
        System.out.println(obj2.equals(obj3)); 
        System.out.println(obj3.equals(obj4)); 
        System.out.println(obj4.equals(obj5)); 
        System.out.println(obj5.equals(obj1)); 
    } 
}
	

boolean-class-example-7.JPG


9. int compareTo(Boolean b)

Syntax:

	
public int compareTo(Boolean b)
	

Example:

	
public class booleanDemo1
{ 
    public static void main(String[] args) 
    { 
        Boolean obj1 = new Boolean("True"); 
        Boolean obj2 = new Boolean(null);
        Boolean obj3 = new Boolean("StUdYtONiGhT"); 
        Boolean obj4 = new Boolean("STUDYTONIGHT"); 
        Boolean obj5 = new Boolean("studytonight"); 

		System.out.println(obj1.compareTo(obj2)); 
        System.out.println(obj2.compareTo(obj3)); 
        System.out.println(obj3.compareTo(obj4)); 
        System.out.println(obj4.compareTo(obj5)); 
        System.out.println(obj5.compareTo(obj1)); 
    } 
}
	

boolean-class-example


10. int compare(boolean x, boolean y)

Syntax:

	
public static int compare(boolean x, boolean y)
	

Example:

	
public class booleanDemo1
{ 
    public static void main(String[] args) 
    { 
        boolean obj1 = true;
        boolean obj2 = false;
        boolean obj3 = true;
        boolean obj4 = false;
        boolean obj5 = true;

		System.out.println(Boolean.compare(obj1, obj2)); 
        System.out.println(Boolean.compare(obj2, obj3)); 
        System.out.println(Boolean.compare(obj3, obj4)); 
        System.out.println(Boolean.compare(obj4, obj5)); 
        System.out.println(Boolean.compare(obj5, obj1)); 
    } 
}
	

boolean-class-example