Java: How to fix ArrayIndexOutOfBoundsException?
<pre><code>public class TextFileExtractor{
    public static String[] fileExtractor(String[] s){

        StringBuilder sb=new StringBuilder();

            for(int i=0;i&lt;=s.length;i++){
                if(s[i].endsWith(".txt")){
                    sb.append(s[i]);
                    sb.append(',');
                }
            }
        String str=sb.toString();
        String[] sa=str.split(",");

        return sa;
    }
}

import java.util.*;

class P8Test{

    public static void main(String[] args) 
    {   Scanner scn=new Scanner(System.in);
        System.out.print("Enter String Array:");
        String[] data=new String[(scn.nextLine()).length()];
        data=(scn.nextLine()).split(",");

            System.out.print("all Files");
                System.out.print(Arrays.toString(data));
                    System.out.print("Text Files");

        String[] res=TextFileExtractor.fileExtractor(data);
        System.out.print(Arrays.toString(res));
    }
}
</code></pre>
