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
 

Example:

public class comptest {

public static void main(String[] args) {

String s = “java”;

String s1 = new String (“java1″);

System.out.println(s.compareTo(s1));

System.out.println(s.equals(s1));

}}


output: -1
            false

Read More →
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!