Click here to watch in Youtube :
https://www.youtube.com/watch?v=dYIbomIlMNo&list=UUhwKlOVR041tngjerWxVccw
Click the below Image to Enlarge
Java Tutorial : Java wrapper class(compareTo method) |
public class WrapperClassTest { public static void main(String[] args) { Integer integerObj1 = new Integer(10); Integer integerObj2 = new Integer(10); /* * public int compareTo(Integer anotherInteger) * * Parameters: * ---------- * * anotherInteger - the Integer to be compared. * * Returns: * ------- * * the value 0 if this Integer is equal to the * argument Integer; a value less than 0 if this * Integer is numerically less than the argument * Integer; and a value greater than 0 if this * Integer is numerically greater than the argument * Integer (signed comparison). */ int result = integerObj1.compareTo(integerObj2); System.out.println("result = " + result); if (result == 0) { System.out.println(integerObj1 + " is equal to " + integerObj2); } else if (result == -1) { System.out.println(integerObj1 + " is less than " + integerObj2); } else if (result == 1) { System.out.println(integerObj1 + " is greater than " + integerObj2); } } }
result = 0 10 is equal to 10
https://sites.google.com/site/javaee4321/java/WrapperClassDemo_CompareTo_method.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/WrapperClassDemo_CompareTo_method
Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/cedeb080226a76d0729219432daf4c1927cf3540/BasicJava/WrapperClassDemo_CompareTo_method/?at=master
See also:
No comments:
Post a Comment