Which datatype is used in compare to?

The String data type is sued to compareTo() method in java. It used for comparing two string and return 0 if the both string are same. other wise the return integer value which is difference between two strings.

Example:

class Compare
{
public static void main(String arr[])
{
String str1=”AMIT”;
String str2=”AJAY”;
int diff;
diff=str1.compareTo(str2);
System.out.println(“Difference :”+diff);
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Show Buttons
Hide Buttons