Sam
0
Q:

method to compare two strings lexicographically.

s1.compareTo(s4)
1
// Java program to show how to compare Strings 
// using library function 
public class Test 
{ 
    public static void main(String[] args) 
    { 
        String s1 = "Ram"; 
        String s2 = "Ram"; 
        String s3 = "Shyam"; 
        String s4 = "ABC"; 
  
        System.out.println(" Comparing strings with compareTo:"); 
        System.out.println(s1.compareTo(s2)); 
        System.out.println(s1.compareTo(s3)); 
        System.out.println(s1.compareTo(s4)); 
    } 
} 
0

New to Communities?

Join the community