java : For loop isn't breaking after reaching a particular condition .
<p>I am in the process of reading only latest 10 Files (by creation date ) from a folder using apache.commons jar </p>

<p>This is listing all the files , but i don't know why this isn't stopping even after completion of reading 10 files </p>

<p>This is my code , but i don't know why it is not stopping </p>

<pre><code>import org.apache.commons.io.comparator.LastModifiedFileComparator;
import java.io.File;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        File dir = new File("D:\\MyFolder");
        File[] files = dir.listFiles();

        Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_REVERSE);
        for (int i = 0; i &lt; files.length; i++) {

             if(files.length==10)
             {
             // return;
                 break ; 
             }

            File file = files[i];
            System.out.printf(file.getName()+"\n");


        }


    }
}
</code></pre>
