String is a sequence of characters. In Java, objects of String are immutable which means they are constant and cannot be changed once created.
Below are 5 ways to compare two Strings in Java:
- Using user-defined function : Define a function to compare values with following conditions :
- if [string1 > string2] it returns a positive value.
- if both the strings are equal lexicographically
i.e.[string1 == string2] it returns 0. - if [string1 < string2] it returns a negative value.
The value is calculated as [int]str1.charAt[i] – [int]str2.charAt[i]
Examples:
Input 1: GeeksforGeeks Input 2: Practice Output: -9 Input 1: Geeks Input 2: Geeks Output: 0 Input 1: GeeksforGeeks Input 2: Geeks Output: 8
Program:
Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
6Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
7Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
8Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
9str1.equals[str2];
0str1.equals[str2];
1str1.equals[str2];
2str1.equals[str2];
1str1.equals[str2];
4str1.equals[str2];
1str1.equals[str2];
6str1.equals[str2];
1Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
7str1.equals[str2];
9Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
0Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
1str1.equals[str2];
1Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
3str1.equals[str2];
0Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
0Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
7Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
0Comparing Geeksforgeeks and Practice : false Comparing Geeks and Geeks : true Comparing Geeks and geeks : false Comparing Geeksforgeeks and Geeks : false
0Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
0Comparing Geeksforgeeks and Practice : false Comparing Geeks and Geeks : true Comparing Geeks and geeks : false Comparing Geeksforgeeks and Geeks : false
3str1.equals[str2];
0Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : false Comparing Geeks and Geeks : true Comparing Geeks and geeks : false Comparing Geeksforgeeks and Geeks : false
6Comparing Geeksforgeeks and Practice : false Comparing Geeks and Geeks : true Comparing Geeks and geeks : false Comparing Geeksforgeeks and Geeks : false
7Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
0Comparing Geeksforgeeks and Practice : false Comparing Geeks and Geeks : true Comparing Geeks and geeks : false Comparing Geeksforgeeks and Geeks : false
9str2.equalsIgnoreCase[str1];
0str2.equalsIgnoreCase[str1];
1str2.equalsIgnoreCase[str1];
2Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
0str2.equalsIgnoreCase[str1];
4Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
0str2.equalsIgnoreCase[str1];
6str2.equalsIgnoreCase[str1];
2Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
0str2.equalsIgnoreCase[str1];
9Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
0Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: true
1str1.equals[str2];
0str2.equalsIgnoreCase[str1];
2Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: true
4Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: true
5Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: true
6Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: true
7Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: true
8str2.equalsIgnoreCase[str1];
2Comparing Geeksforgeeks and Practice : false Comparing Geeks and Geeks : true Comparing Geeks and geeks : true Comparing Geeksforgeeks and Geeks : false
0Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : false Comparing Geeks and Geeks : true Comparing Geeks and geeks : true Comparing Geeksforgeeks and Geeks : false
0str1.equals[str2];
0Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : false Comparing Geeks and Geeks : true Comparing Geeks and geeks : true Comparing Geeksforgeeks and Geeks : false
5Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : false Comparing Geeks and Geeks : true Comparing Geeks and geeks : true Comparing Geeksforgeeks and Geeks : false
7Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: true
4public static boolean equals[Object a, Object b]
0str2.equalsIgnoreCase[str1];
2Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: true
7public static boolean equals[Object a, Object b]
3Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : false Comparing Geeks and Geeks : true Comparing Geeks and geeks : true Comparing Geeksforgeeks and Geeks : false
0str1.equals[str2];
0Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5public static boolean equals[Object a, Object b]
8Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: null Input 2: null Output: true
0Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: null Input 2: null Output: true
2Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
3str2.equalsIgnoreCase[str1];
2Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: true
7str2.equalsIgnoreCase[str1];
0Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: null Input 2: null Output: true
7Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : false Comparing Geeks and Geeks : true Comparing Geeks and geeks : true Comparing Geeksforgeeks and Geeks : false
0str1.equals[str2];
1Comparing Geeksforgeeks and Practice : false Comparing Geeks and Geeks : true Comparing Geeks and geeks : true Comparing Geeksforgeeks and Geeks : false
0str1.equals[str2];
0str1.equals[str2];
1Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
04str1.equals[str2];
1Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
7str1.equals[str2];
9Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
08Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
09str1.equals[str2];
1Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
3Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
13Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
14Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
15Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
16Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
17Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
19Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
14Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
15Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
22Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
17Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
25Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
14Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
15Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
28Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
17Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
31Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
14Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
15Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
28Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
17str1.equals[str2];
0Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
38Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
40Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
41Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
42Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
43Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
44Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
45Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
46Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
47Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
48str1.equals[str2];
0Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
51Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
40Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
41Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
55Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
43Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
57Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
45Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
46Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
47Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
61str1.equals[str2];
0Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
64Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
40Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
41Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
42Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
43Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
57Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
45Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
46Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
47Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
74str1.equals[str2];
1Comparing Geeksforgeeks and Practice : false Comparing Geeks and Geeks : true Comparing Geeks and geeks : true Comparing Geeksforgeeks and Geeks : false
0Comparing Geeksforgeeks and Practice : false Comparing Geeks and Geeks : true Comparing Geeks and geeks : true Comparing Geeksforgeeks and Geeks : false
0Output:
Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
- Using String.equals[] :In Java, string equals[] method compares the two given strings based on the data/content of the string. If all the contents of both the strings are same then it returns true. If any character does not match, then it returns false.
Syntax:
str1.equals[str2];
Here str1 and str2 both are the strings which are to be compared.
Examples:
Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
Program:
Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
6Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
7Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
8Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
9str1.equals[str2];
1Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
7str1.equals[str2];
9Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
08Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
09str1.equals[str2];
1Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
3Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
13Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
14Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
15Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
16Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
17Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
19Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
14Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
15Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
22Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
17Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
25Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
14Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
15Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
28Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
17Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
31Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
14Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
15Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
28Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
17Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5str1.equals[str2];
15Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
14Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
15str1.equals[str2];
18Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
17str1.equals[str2];
0Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5str1.equals[str2];
22Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
40Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
41Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
42Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
43Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
44Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
45Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
46Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
47str1.equals[str2];
32str1.equals[str2];
0Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
51Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
40Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
41Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
55Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
43Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
57Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
45Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
46Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
47str1.equals[str2];
45str1.equals[str2];
0Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5str1.equals[str2];
48Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
40Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
41str1.equals[str2];
52Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
43str1.equals[str2];
54Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
45Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
46Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
47str1.equals[str2];
58str1.equals[str2];
0Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5str1.equals[str2];
61Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
40Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
41Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
42Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
43Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
57Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
45Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
46Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
47str1.equals[str2];
71str1.equals[str2];
1Comparing Geeksforgeeks and Practice : false Comparing Geeks and Geeks : true Comparing Geeks and geeks : true Comparing Geeksforgeeks and Geeks : false
0Comparing Geeksforgeeks and Practice : false Comparing Geeks and Geeks : true Comparing Geeks and geeks : true Comparing Geeksforgeeks and Geeks : false
0Output:
Comparing Geeksforgeeks and Practice : false Comparing Geeks and Geeks : true Comparing Geeks and geeks : false Comparing Geeksforgeeks and Geeks : false
- Using String.equalsIgnoreCase[] : The String.equalsIgnoreCase[] method compares two strings irrespective of the case [lower or upper] of the string. This method returns true if the argument is not null and the contents of both the Strings are same ignoring case, else false.
Syntax:
str2.equalsIgnoreCase[str1];
Here str1 and str2 both are the strings which are to be compared.
Examples:
Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: true
Program:
Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
6Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
7Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
8Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
9str1.equals[str2];
1Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
7str1.equals[str2];
9Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
08Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
09str1.equals[str2];
1Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
3Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
13Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
14Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
15Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
16Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
17Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
19Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
14Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
15Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
22Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
17Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
25Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
14Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
15Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
28Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
17Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
31Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
14Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
15Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
28Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
17Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5str1.equals[str2];
15Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
14Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
15str1.equals[str2];
18Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
17str1.equals[str2];
0Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5str1.equals[str2];
22Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
40Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
41Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
42Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
43Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
44Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
45Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
46Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
47Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
29str1.equals[str2];
0Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
51Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
40Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
41Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
55Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
43Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
57Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
45Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
46Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
47Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
42str1.equals[str2];
0Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
45Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
40Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
41str1.equals[str2];
52Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
43str1.equals[str2];
54Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
45Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
46Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
47Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
55str1.equals[str2];
0Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5str1.equals[str2];
61Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
40Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
41Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
42Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
43Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
57Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
45Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
46Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
47Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
68str1.equals[str2];
1Comparing Geeksforgeeks and Practice : false Comparing Geeks and Geeks : true Comparing Geeks and geeks : true Comparing Geeksforgeeks and Geeks : false
0Comparing Geeksforgeeks and Practice : false Comparing Geeks and Geeks : true Comparing Geeks and geeks : true Comparing Geeksforgeeks and Geeks : false
0Output:
Comparing Geeksforgeeks and Practice : false Comparing Geeks and Geeks : true Comparing Geeks and geeks : true Comparing Geeksforgeeks and Geeks : false
- Using Objects.equals[] : Object.equals[Object a, Object b] method returns true if the arguments are equal to each other and false otherwise. Consequently, if both arguments are null, true is returned and if exactly one argument is null, false is returned. Otherwise, equality is determined by using the equals[] method of the first argument.
Syntax:
public static boolean equals[Object a, Object b]
Here a and b both are the string objects which are to be compared.
Examples:
Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: null Input 2: null Output: true
Program:
Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
6str1.equals[str2];
0Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
75Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
76str1.equals[str2];
0Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
7Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
8Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
9str1.equals[str2];
1Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
7str1.equals[str2];
9Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
08Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
09str1.equals[str2];
1Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
3Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
13Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
14Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
15Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
16Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
17Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
19Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
14Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
15Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
28Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
17Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
25Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
14Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
15Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
28Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
17Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
31Comparing Geeksforgeeks and Practice : false Comparing Geeks and Geeks : true Comparing Geeks and geeks : false Comparing Geeksforgeeks and Geeks : false
08Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: null Input 2: null Output: true
7Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5str1.equals[str2];
15Comparing Geeksforgeeks and Practice : false Comparing Geeks and Geeks : true Comparing Geeks and geeks : false Comparing Geeksforgeeks and Geeks : false
08Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: null Input 2: null Output: true
7str1.equals[str2];
0Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5str1.equals[str2];
22Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
40Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
41Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
42Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
43Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
44Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
45Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
46Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
47Comparing Geeksforgeeks and Practice : false Comparing Geeks and Geeks : true Comparing Geeks and geeks : false Comparing Geeksforgeeks and Geeks : false
26str1.equals[str2];
0Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : false Comparing Geeks and Geeks : true Comparing Geeks and geeks : false Comparing Geeksforgeeks and Geeks : false
29Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
40Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
41Comparing Geeksforgeeks and Practice : false Comparing Geeks and Geeks : true Comparing Geeks and geeks : false Comparing Geeksforgeeks and Geeks : false
33Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
43Comparing Geeksforgeeks and Practice : false Comparing Geeks and Geeks : true Comparing Geeks and geeks : false Comparing Geeksforgeeks and Geeks : false
35Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
45Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
46Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
47Comparing Geeksforgeeks and Practice : false Comparing Geeks and Geeks : true Comparing Geeks and geeks : false Comparing Geeksforgeeks and Geeks : false
39str1.equals[str2];
0Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5str1.equals[str2];
61Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
40Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
41Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
42Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
43Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
57Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
45Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
46Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
47Comparing Geeksforgeeks and Practice : false Comparing Geeks and Geeks : true Comparing Geeks and geeks : false Comparing Geeksforgeeks and Geeks : false
52str1.equals[str2];
0Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
45Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
40Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
41str1.equals[str2];
52Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
43str1.equals[str2];
54Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
45Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
46Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
47Comparing Geeksforgeeks and Practice : false Comparing Geeks and Geeks : true Comparing Geeks and geeks : false Comparing Geeksforgeeks and Geeks : false
65str1.equals[str2];
1Comparing Geeksforgeeks and Practice : false Comparing Geeks and Geeks : true Comparing Geeks and geeks : true Comparing Geeksforgeeks and Geeks : false
0Comparing Geeksforgeeks and Practice : false Comparing Geeks and Geeks : true Comparing Geeks and geeks : true Comparing Geeksforgeeks and Geeks : false
0Output:
Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
0 - Using String.compareTo[] :
Syntax:
Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
1Working:
It compares and returns the following values as follows:- if [string1 > string2] it returns a positive value.
- if both the strings are equal lexicographically
i.e.[string1 == string2] it returns 0. - if [string1 < string2] it returns a negative value.
Examples:
Input 1: GeeksforGeeks Input 2: Practice Output: -9 Input 1: Geeks Input 2: Geeks Output: 0 Input 1: GeeksforGeeks Input 2: Geeks Output: 8
Program:
Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
6str1.equals[str2];
0Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
75Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
76str1.equals[str2];
0Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
7Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
8Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
9str1.equals[str2];
1Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
7str1.equals[str2];
9Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
08Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
09str1.equals[str2];
1Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
3Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
13Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
14Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
15Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
16Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
17Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
19Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
14Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
15Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
22Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
17Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
25Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
14Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
15Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
28Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
17Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
31Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
14Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
15Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
28Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
17str1.equals[str2];
0Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
38Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
40Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
41Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
42Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
43Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
44Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
45Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
46Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
47str2.equalsIgnoreCase[str1];
21str1.equals[str2];
0Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
51Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
40Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
41Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
55Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
43Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
57Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
45Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
46Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
47str2.equalsIgnoreCase[str1];
34str1.equals[str2];
0Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
64Input 1: GeeksforGeeks Input 2: Practice Output: false Input 1: Geeks Input 2: Geeks Output: true Input 1: geeks Input 2: Geeks Output: false
5Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
40Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
41Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
42Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
43Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
57Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
45Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
46Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
47str2.equalsIgnoreCase[str1];
47str1.equals[str2];
1Comparing Geeksforgeeks and Practice : false Comparing Geeks and Geeks : true Comparing Geeks and geeks : true Comparing Geeksforgeeks and Geeks : false
0Comparing Geeksforgeeks and Practice : false Comparing Geeks and Geeks : true Comparing Geeks and geeks : true Comparing Geeksforgeeks and Geeks : false
0Output:
Comparing Geeksforgeeks and Practice : -9 Comparing Geeks and Geeks : 0 Comparing Geeksforgeeks and Geeks : 8
Why not to use == for comparison of Strings?
In general both equals[] and “==” operator in Java are used to compare objects to check equality but here are some of the differences between the two:
- Main difference between .equals[] method and == operator is that one is method and other is operator.
- One can use == operators for reference comparison [address comparison] and .equals[] method for content comparison.
In simple words, == checks if both objects point to the same memory location whereas .equals[] evaluates to the comparison of values in the objects.