how does Collections.binarySearch() with comparator work when the input is not in sorted? : <p>I am confused that this method doesn't work as expected:</p>

<p>public static  int binarySearch(List list,
                   T key,
                   Comparator c)</p>

<p>here is my code</p>

<pre><code>// Create a list 
    List&lt;Domain&gt; l = new ArrayList&lt;Domain&gt;(); 
    l.add(new Domain(10, "quiz.geeksforgeeks.org")); 
    l.add(new Domain(70, "practice.geeksforgeeks.org")); 
    l.add(new Domain(30, "code.geeksforgeeks.org")); 
    l.add(new Domain(40, "www.geeksforgeeks.org")); 
    l.add(new Domain(20, "practice.geeksforgeeks.org")); 
    l.add(new Domain(21, "practice.geeksforgeeks.org")); 



    // Searching a domain with key value 10. To search 
    // we create an object of domain with key 10. 
    int index = Collections.binarySearch(l, 
                             new Domain(31, null),new Comparator&lt;Domain&gt;() 
                             { 
                                 public int compare(Domain u1, Domain u2) 
                                 { 
                                     return u1.getId().compareTo(u2.getId()); 
                                 } 
                             }); 
    System.out.println("Found at index  " + index); 
</code></pre>

<p>it returns -7 to me which is not correct.
From the documentation, it says "The list must be sorted into ascending order according to the specified comparator". Here the sorted list should be :Domain(10...,20,21,30,40,70
I didnt see why the -7?</p>
