1public int compareTo(Jedi jedi){
2 return this.age > jedi.age ? 1 : this.age < jedi.age ? -1 : 0;
3}
4
1******Java String compareTo()******
2
3 The Java String class compareTo() method compares the given
4 string with the current string lexicographically.
5 It returns a positive number, negative number, or 0.
6 ___________________________________________
7 if s1 > s2, it returns positive number
8 if s1 < s2, it returns negative number
9 if s1 == s2, it returns 0
10 ___________________________________________
11
12
1String myStr1 = "Hello";
2String myStr2 = "Hello";
3System.out.println(myStr1.compareTo(myStr2)); // Returns 0 because they are equal