I've been trying to get the code for this but i still cant. This code segment is the closest I can do. What am I missing? I am trying to do this code without Hash.
// Read all the words from the dictionary (text.txt) into an array
BufferedReader br = new BufferedReader(new FileReader("text.txt"));
int bufferLength = 1000000;
char[] buffer = new char[bufferLength];
int charsRead = br.read(buffer, 0, bufferLength);
br.close();
String text = new String(buffer);
text = text.trim();
text = text.toLowerCase();
String[] words = text.split("\n");
System.out.println("Total number of words in text: " + words.length);
//Find unique words:
String[] uniqueText = words;
int[] uniqueTextCount = new int[uniqueText.length];
for (int i = 0; i < words.length; i++) {
for (int j = 0; j < uniqueText.length; j++) {
if (words[i].equals(uniqueText[j])) {
uniqueTextCount[j]++;
} else {
uniqueText[i] = words[i];
}
}
System.out.println(uniqueText[i] + " for " + uniqueTextCount[i]);
}
}