import java.util.ArrayList; public class Analyser { public static ArrayList countElements(ArrayList uniqueWordList, ArrayList allWordsList) { ArrayList individualWordCount = new ArrayList<>(); for (int i = 0; i < uniqueWordList.size(); i++) { individualWordCount.add(0); } for (String word : allWordsList) { int wordCount = individualWordCount.get(uniqueWordList.indexOf(word)); individualWordCount.set(uniqueWordList.indexOf(word), ++wordCount); } return individualWordCount; } public static String[] frequentWords(ArrayList uniqueWordList, ArrayList wordCounts) { ArrayList wordsCopy = new ArrayList<>(uniqueWordList); ArrayList countsCopy = new ArrayList<>(wordCounts); String[] frequentWords = new String[10]; for (int i = 0; i < frequentWords.length; i++) { if (wordsCopy.isEmpty()) { break; } int highestFrequency = 0; int highestIndex = 0; for (int j = 0; j < wordsCopy.size(); j++) { if (countsCopy.get(j) > highestFrequency) { highestFrequency = countsCopy.get(j); highestIndex = j; } } frequentWords[i] = wordsCopy.get(highestIndex); countsCopy.remove(highestIndex); wordsCopy.remove(highestIndex); } return frequentWords; } }