 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Case sensitive string comparison in Java
You can compare two strings using either the equals() method or the compareTo() method.
Where,
- The equals() method compares this string to the specified object.
- The compareTo() method compares two strings lexicographically. The comparison is based on the Unicode value of each character in the strings.
These two methods compare the given strings with respective to Case i.e. String with the different case are treated differently.
Example
The following example demonstrates the comparison of two strings using the equals() method ?
public class Sample{ public static void main(String args[]) { String str = "Hello World"; String anotherString = "hello world"; Object objStr = str; System.out.println( str.equals(anotherString) ); } } Output
false
Advertisements
 