Scala Programming: Compare two strings lexicographically
Write a Scala program to compare two strings lexicographically.
Note: Two strings are lexicographically equal if they are the same length and contain the same characters in the same positions.
Sample Solution:
Scala Code:
Sample Output:
ring 1: This is Exercise 1 String 2: This is Exercise 2 "This is Exercise 1" is less than "This is Exercise 2" ======================== String 1: This is Exercise 1 String 2: This is Exercise 1 "This is Exercise 1" is equal to "This is Exercise 1" ======================== String 1: This is Blacky String 2: This is Black "This is Blacky" is greater than "This is Black"
Scala Code Editor :
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Scala program to get the character (Unicode code point) at the given index within the String.
Next: Write a Scala program to concatenate a given string to the end of another string.
What is the difficulty level of this exercise?