❮ Previous Next ❯

Comparable Interface

Example:

obj1.compareTo(obj2);

Let's see a demo program of compareTo() method:

TreeSetDemo2.java

import java.util.*;
class ComparableDemo
{
public static void main(String args[])
{
System.out.println("A".compareTo("Z"));
System.out.println("Z".compareTo("B"));
System.out.println("A".compareTo("A"));
System.out.println("A".compareTo(null));
}
}

Output

-25
24
0

Note

❮ Previous Next ❯



  Tutorials

Popular Links

Contact Us

address Plot No-741,2ND Floor
Opp. Bhagabati Temple,Jayadev Vihar
      Bhubaneswar-751013
      Email: info@silantechnology.com
      Phone: 0674-2361252
address
39877, sundale dr, apt#101, Fremont, California 94538, USA
       Phone: +1(262)388-7619

facebook twitter google linked in

© 2018 Silan Technology. All Rights Reserved