Comparing Lexicographically Java Code Example

Snippet 1

  s1.compareTo(s4) 

Snippet 2

  // 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)); 
    } 
} 
 

Copyright © Code Fetcher 2020

 

 

Published

Leave a comment

Your email address will not be published. Required fields are marked *