So, I'm trying to compare two String in Java right now. But the compareTo() method works weird. Consider this example:
String one = "one";
String two = "this is muuch greater";
System.out.println(one.compareTo(two));
And if I try to compare them the method works just fine. It returns a negative value.
But if I try something different, for example: (1)
String one = "word";
String two = "hello world";
System.out.println(one.compareTo(two));
or something like this: (2)
String one = "key";
String two = "qw";
System.out.println(one.compareTo(two));
It acts all weird. In the (1) case the method returned a positive value, despite String one being shorter than the String two
In the (2) case the method returned a negative value, despite the first string being longer than the other one.
It says, that the compareTo() method returns a positive value if the string to which the method is "applied" is longer than the string passing into arguments. The method returns 0 if their length is equal and returns a negative value in every other case. What is wrong am i doing?