Example & Tutorial understanding programming in easy ways.

What is difference between Compare to and equals method in java?.

ComapareTo () method is provided by java.lang.string package that check the two different String to character by character if both the String are same than return 0 otherwise it return (-value) for each character.

Equals () Method is java. Object package Object Class Method that Check the two Different object and return true or false


public class comptest {

public static void main(String[] args) {

String s = “java”;

String s1 = new String (“java1″);




output: -1

Read More →