There are a couple of things you should think about or fix:
Indentation. You're not really consistent in indenting your code. Please follow the Java conventions.
No need to call
super()inside your constructor, the default empty super constructor is automatically called.Use "constructor chaining" in
WordArrayList, andTextAnalyzer. That is, call one constructor from another. For example,public TextAnalyzer(String text) { this(text, REG_SPLIT_EXP); }You have a whole lot of unnecessary methods: setWords
setWords, getWordsgetWords, setWordCountsetWordCount, setWordsetWord. You don't use them and I really don't think that you need them.Use
private finalfor fields that should be initialized once and then never change, such asprivate final String word;in theWordDataclass. Apply this wherever possible.private int position;is not used inWordData, and I don't think you need to use it either. Select and press the Delete button on your keyboardI suggest naming the class
WordListinstead. The fact that it uses an array is not important. It is a List of words, how the internal list works is not needed for the user to knowCalling
generateWordArrayListmultiple times would produce strange results.convertToArrayis private, contains one line, and is only called from one location: Does it really need to be it's own method?Use a "for-each" loop to improve readability when iterating:
for (String str : splitTextArray)You can store the number of times each word occurs with a
HashMap<String, Integer>instead. To initialize the HashMap, you can use this:Map<String, Integer> words = new HashMap<String, Integer>(); for (String str : splitTextArray) { if (words.containsKey(str)) words.put(str, words.get(str) + 1); else words.put(str, 1); }Note that you can use
TreeMapinstead ofHashMapto keep the keys in a sorted order, so that if you iterate overwords.entrySet(), you will always iterate in sorted order. (You can also provide a customComparatorto the TreeMap if you are not satisfied with the built-in sorting)
Overall the current classes you have seems to do what they are supposed to do, and the result is correct. Good job.