Hi as it stands im currently using processing and learning java, my code essentially works its way through an ArrayList and finds the word which occurs most and outputs it to the console, my code is below:
import java.util.Arrays;
ArrayList<String> words = new ArrayList();
int[] occurrence = new int[2000];
void setup() {
size(800,480);
smooth();
String[] data = loadStrings("data/data.txt");
Arrays.sort(data);
for (int i = 0; i < data.length; i ++ ) {
words.add(data[i]);
words.add(data[j]); //Put each word into the words ArrayList
}
for(int i =0; i<data.length; i++) {
occurrence[i] =0;
for(int j=i+1; j<data.length; j++) {
if(data[i].equals(data[j])) {
occurrence[i] = occurrence[i]+1;
}
}
}
int max = 0;
String most_talked ="";
for(int i =0;i<data.length;i++) {
if(occurrence[i]>max) {
max = occurrence[i];
most_talked = data[i];
}
}
println("The most talked keyword is " + most_talked + " occuring " + max + " times.");
I am wondering how I would go about altering it to add in the 2nd most occurring word, and so on and so forth.
I have looked into using a map, as well as collection.sort but cant quite get how to move forward with this. I am fairly new to java so anything at all would be helpful.