3:50 pm - Monday February 19, 2734

String Program using compareToIgnoreCase(String str) method

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

// StringĀ  Program using compareToIgnoreCase(String str) method */

class CompareIgnoreCase{
public static void main(String[] args){
String s1="Welcome To CaNdiD";
String s2="WELCOME to candid";
int comp=s1.compareToIgnoreCase(s2);
/* compareToIgnoreCase(String str) method compare two strings and ignore case differences(Upper or Lower case).
Returns negative if the first string(s1) is less than second string(s2),
Returns positive if the first string is greater than second string, Returns zero if both same, ignoring case differences.
*/
if(comp>0){
System.out.println("The first string(s1) is greater than second string(s2)");
}else if(comp==0){
System.out.println("Both strings have the same value");
}else{
System.out.println("The second string(s2) is greater than first string(s1)");
}
}
}

Output:
E:\String>javac CompareIgnoreCase.java

E:\String>java CompareIgnoreCase
Both strings have the same value
*/

Filed in: Z-A All Java Codes

No comments yet.

Leave a Reply