title: lexicographical comparison of two arrays in java
body: <p>I would like to implement a method that takes 2 arrays and returns the one that is lexicographically smaller than the other. I tried to do it according to the definition of lexicographic order, but it does not work. Here is my code:</p>
  
  <pre><code>public boolean lexicoSmaller(ArrayList&lt;Integer&gt; list1, ArrayList&lt;Integer&gt; list2)
  {
      int m = 1;
      int n = list1.size() -1;
  
  
      while(m &lt;= n)
      {
          boolean firstFound = true;
          for(int i=0; i&lt;m; i++)
          {
              if(!Objects.equals(list1.get(i), list2.get(i)))
              {
                  firstFound = false;
                  break;
              }
          }
  
          if(firstFound &amp;&amp; list1.get(m) &lt; list2.get(m)) return true;
          m++;
      }
  
      return false;
  }
  </code></pre>
  
  <p>The code above doesn't give the right answer. </p>
  
  <p>For example for the inputs <code>0 5 7 9 14 16 18 23</code> and <code>1 3 6 11 12 17 20 22</code>, the answer should be true, but I got false.</p>