HOME      BLOG       FORUMS      CONTACT       ABOUT

Compare two Boolean objects

The compareTo method of Boolean wrapper class is used for comparing two Boolean objects.

public class BooleanWrapper {
	public static void main(String[] args) {
		Boolean b = new Boolean(true);
		Boolean b1 = new Boolean(false);

		if (b.compareTo(b1) == 0) {
			System.out.println("Both objects are equal.");
		}
		else if (b.compareTo(b1) > 0) {
			System.out.println("b is true.");
		}
		else {
			System.out.println("b is false");
		}
	}
}

Share

Tags: , , , ,


You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

AddThis Social Bookmark Button

Leave a Reply