title: What is string lexicographically? Java
body: <p>The compareTo() method in Java compares two strings "lexicographically". Can someone please simply explain how the lexicographic comparison works in java?</p>
  
  <p>I found <strong><a href="https://stackoverflow.com/questions/4064633/string-comparison-in-java">this post</a></strong> that explains the three cases of &lt;0 , ==0, and >0 ; However, I am still confused...</p>
  
  <p>Does this mean that the int returned is the number of places away the strings are form one another if they were to be sorted alphabetically like a dictionary? </p>
  
  <p>Also, how does the method deal with case sensitivity? Are lower case letters first in line before uppercase? Is there a chart for this?</p>
  
  <p>For example, the below code produces an output of -31. Does this mean that the string Dog is -31 places away from the string cat?</p>
  
  <pre><code>public static void main(String[] args) {
       Scanner keyboard = new Scanner(System.in);   
  
       String str1 = "Dog";
  
       String str2 = "cat";
  
       int result = str1.compareTo(str2);
       System.out.println(result);
  </code></pre>