compareTo in java code example
Example 1: java how to compare strings
System.out.println("hey".equals("hey"));
Example 2: string compare java ==
new String("test").equals("test")
new String("test") == "test"
new String("test") == new String("test")
Example 3: compareto method java
public int compareTo(Jedi jedi){
return this.age > jedi.age ? 1 : this.age < jedi.age ? -1 : 0;
}
Example 4: compare to java
String myStr1 = "Hello";
String myStr2 = "Hello";
System.out.println(myStr1.compareTo(myStr2));