String methods compareto VS equals in java

https://‮ttual.www‬uri.com
String methods compareto VS equals in java

Using compareTo() when you need to know the difference in length between strings that start with the same sequence of characters.

/**
 * @author lautturi.com 
 * Java example: difference between compareto and equals in java
 */

import java.util.*;

public class Lautturi {
	public static void main(String[] args) {
		System.out.println("hello".compareTo("olleh"));
		System.out.println("hello".equals("olleh"));
		System.out.println("hello".compareTo("hallo"));
	}
}

output:

-7
false
4

e - a = 4.

Created Time:2017-10-17 23:25:07  Author:lautturi