Word counter for text files I've made a program that works, but i want to make it reusable. This code reads in a dictionary object created in another class (that i made), as well as read in a text file to put in said dictionary object. The code then loads in another text file, compares it with the dictionary, updates its frequency values and outputs to a vector. Everything works, but as i said i'm looking to make it reusable. What i mean by this is once the values have been stored in the vector, i'd like the dictionaries frequency values to reset back to 0, ready for the next text document to be compared with the dictionary, then output that to a different vector - this process will be repeated 10-12 times.

String Counter

public class StringCounter {

private LinkedList&lt;Integer&gt; list = new LinkedList&lt;&gt;();

public StringCounter(LinkedList&lt;Integer&gt; list) {
    this.list = list;
}

public static void main(String[] args) {

    HashMap&lt;String, Integer&gt; dictionary = new HashMap&lt;String, Integer&gt;();

    List&lt;String&gt; textFileList = Arrays.asList("Test.txt", "Test2.txt");

    try {

        Dictionary reader = new Dictionary(dictionary);

        for (String text : textFileList) {
            reader.fileScanner(text);
        }

        Scanner textFile = new Scanner(new File("Test4.txt"));
        ArrayList&lt;String&gt; file = new ArrayList&lt;String&gt;();

        while(textFile.hasNext()) {
            file.add(textFile.next().trim().toLowerCase());
        }

        for(String word : file) {
            Integer dict = dictionary.get(word);
            if (!dictionary.containsKey(word)) {
                    dictionary.put(word, 1); 
            } else {
                    dictionary.put(word, dict + 1);
            }
        }

        textFile.close();

        } catch(FileNotFoundException e){
            e.printStackTrace();
        } 

    Vector&lt;Integer&gt; vec1 = new Vector&lt;&gt;(dictionary.values());

    for (Integer count : vec1) {
        System.out.println(count);
    }   
}
}


Dictionary

public class Dictionary {
    // Declare set in a higher scope (making it a property within the object)
    private HashMap&lt;String, Integer&gt; dictionary = new HashMap&lt;String, Integer&gt;();

    // Assigns the value of the parameter to the field of the same name
    public Dictionary(HashMap&lt;String, Integer&gt; dictionary) {
        this.dictionary = dictionary;
    }

    // Gets input text file, removes white spaces and adds to dictionary object
    public void fileScanner(String textFileName) {
        try {

            Scanner textFile = new Scanner(new File(textFileName));

            while (textFile.hasNext()) {
                 dictionary.put(textFile.next().trim(), 0);
            }

            textFile.close();

        } catch (FileNotFoundException e) {
             e.printStackTrace();
        }
    }

    public void printDict(HashMap&lt;String, Integer&gt; dictionary) {
        System.out.println(dictionary.keySet());
    }    
}
Usage of interfaces

HashMap&lt;String, Integer&gt; dictionary = ...


Try to use interfaces on the lefthand side as a best practice: Map, List,  ... as it will make you independent of hashmap, linkedhashmap,...

also try not to use vector unless really necessary (https://stackoverflow.com/questions/2986296/what-are-the-differences-between-arraylist-and-vector)

Naming

HashMap&lt;String, Integer&gt; dictionary = new HashMap&lt;String, Integer&gt;(); 
...
Dictionary reader = new Dictionary(dictionary);


There is a class dictionary, a map with the same name and when initalizing an instance of Dictionary, then it is called "reader". This is confusing

reader.fileScanner(text)


This method name does not really indicate an action. reader.scanFile(text) would be better.

Reusing dictionary data

you could make the counting of the words a method of the dictionary where you build a new map with only a count for the words encountered in the new text file(s) and return that map.

Comments

avoid comments like 

// Assigns the value of the parameter to the field of the same name


as they describe what you do in the code, which you can see by reading the code. When putting a comment then at least tell why some piece of code is implemented as such (specific issue, specific algorithm, ...)

Error handling

e.printstacktrace is by preference replaced by a logging framework (log4j2, logback, slf4j as façade, ...)
Perhaps you can make the method throw ioException and make the calling code handle this?