Write a program Compare on String to other using java - Technology369kk

Program:

class StringCompare {
public static void main(String arg[]){
String str1 ="Hello";
String str2 ="World";

// Compare two string
int result= str1.compareTo(str2);

if ( result == 0) {
System.out.println("Both Strings are equal");
}else if( result < 0){
System.out.println(str1 +" comes before "+ str2);
}else{
System.out.println(str1 +" comes after n "+ str2);
}
}
}



Answer:



Hello comes before World
 

Post a Comment

0 Comments