ContactUs :

Please send your Questions & Answers or Feedback to "mohan@javabook.org"

How to Compare String in Java ?

String is immutable in Java and one of the most used value class. For comparing String in Java we should not be worrying because String implements Comparable interface and provides a lexicographic implementation for CompareTo method which compare two strings based on contents of characters or you can say in lexical order. You just need to call String.compareTo(AnotherString) and Java will determine whether specified String is greater than , equal to or less than current object. See my post 4 example to compare String in Java for alternatives ways of comparing String.

1) String comparison using equals method

2) String comparison using equalsIgnoreCase method

2) String comparison using compareTo method

4) String comparison using compareToIgnoreCase method

Related Posts Plugin for WordPress, Blogger...
Flag Counter