วันอังคารที่ 29 กรกฎาคม พ.ศ. 2557

Java java.lang Boolean compareTo(Boolean b)

Java java.lang Boolean compareTo(Boolean b)

Description Of Boolean: compareTo(Boolean b)


The java.lang.Boolean.compareTo(Boolean b) compares this Boolean instance with another.

Boolean.compareTo(Boolean b) method returns, zero - if this object represents the same boolean value as the argument, a positive value - if this object represents true and the argument represents false, a negative value - if this object represents false and the argument represents true.

Code Example Java Boolean


public class BooleanExam {
 public static void main(String[] args) {
  Boolean x = new Boolean(true);
  Boolean y = new Boolean(false);

  int a = x.compareTo(y);
  String str1 = "Both values are equal ";
  String str2 = "Object value is true";
  String str3 = "Argument value is true";

  if (a == 0) {
   System.out.println(str1);
  } else if (a > 0) {
   System.out.println(str2);
  } else if (a < 0) {
   System.out.println(str3);
  }
 }
}

yengo หรือ buzzcity

ไม่มีความคิดเห็น :

แสดงความคิดเห็น