public static int compare(char[] str1,char[] str2){
  int len1=str1.length;
  int len2=str2.length;
  int n=Math.min(len1,len2);
  int i=0;
  while (n-- != 0) {
    char c1=str1[i];
    char c2=str2[i++];
    if (c1 != c2) {
      return c1 - c2;
    }
  }
  return len1 - len2;
}

public static int compare ( char [ ] str1 , char [ ] str2 ) { int len1 = str1 . length ; int len2 = str2 . length ; int n = Math . min ( len1 , len2 ) ; int i = 0 ; while ( n -- != 0 ) { char c1 = str1 [ i ] ; char c2 = str2 [ i ++ ] ; if ( c1 != c2 ) { return c1 - c2 ; } } return len1 - len2 ; }
compares two strings lexicographically . the comparison is based on the unicode value of each character in the strings .
