how to let the size of array to grow and shrink automatically?
<pre><code>            int filename = 100;
    String[] fileName = new String[filename];
    int a = 0;
    int totalCount = 0;
    int wordCount = 0;

    // Count the number of documents containing the query

    System.out.println("Please enter the query  :");
    Scanner scan2 = new Scanner(System.in);
    String word2 = scan2.nextLine();
    String[] array2 = word2.split(" ");
    int[] numofDoc = new int[array2.length];

    for (int b = 0; b &lt; array2.length; b++) {

        numofDoc[b] = 0;

        for (int i = 0; i &lt; filename; i++) {

            try {

                BufferedReader bf = new BufferedReader(new FileReader(
                        "C:\\Users\\user\\fypworkspace\\FYP\\abc"
                                + i + ".txt"));

                int matchedWord = 0;

                Scanner s2 = new Scanner(bf);

                {

                    while (s2.hasNext()) {
                        if (s2.next().equals(array2[b]))
                            matchedWord++;
                    }

                }
                if (matchedWord &gt; 0)
                    numofDoc[b]++;

            } catch (IOException e) {
                System.out.println();
            }

        }
        _resultArea.append(array2[b]
                + " --&gt; This number of files that contain this term  "
                + numofDoc[b]+ newline);
    }
</code></pre>

<p>hi, this is my code for calculating number of files that contain a specific input keyed in by the user. This code analyze a folder of text files and search the text files whether it has the input or not. 
The problem i facing now is, i now declaring the array size of 100. It means that it will process 100 text files whether the folder have 100 files or not. <strong>How do i let the program to process exact number of text files inside a folder ?</strong> </p>

<p>Note : The number of text files is dynamic. It doesnt has a constant number of text files inside the folder. </p>
