- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 equals() method or 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
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
- Related Articles
- How MySQL can perform case-sensitive string comparison?
- How to do case-sensitive string comparison in JavaScript?
- How to make SQL case sensitive string comparison in MySQL?
- What kind of string comparison, case-sensitive or not, can be performed by MySQL?
- Case-insensitive string comparison in C++
- How do we make my string comparison case insensitive in java?
- String Comparison in Java
- Case-sensitive sort in JavaScript
- Java Program to sort an array in case-sensitive order
- Java Program to sort a List in case sensitive order
- How to compare two strings without case sensitive in Java
- Java String Comparison Methods.
- Is Python case-sensitive or case-insensitive?
- How do I make my string comparison case insensitive?
- How do I do a case insensitive string comparison in Python?

Advertisements