I've been trying to make and display in JFrame a top five out of 13 options. It goes something like this:
I have a .txt with a bunch of words, let's say apple, banana, orange, etc. And a counter for each word. Then I open the file and scan it with a Scanner and a String, if it finds the word "apple" then it adds 1 to the apple counter. After it scans the whole .txt I put the counters in an array and sort them with Arrays.sort(array);
My problem is that the array only holds the numeric value for each word, so I tried comparing the last position in the array (since it's the highest one) with every counter for each word, and if it matches with any counter I set that one as "Top 1", then I do the same for "Top 2" and the second-to-last in the array and so on.
But this obviously only works if there are no repeated values. If "Apple" and "Orange" both appear 3 times then both will match and then, the program will set the first one matched in the TextField1 and 2.
Is there a way to go around this? Maybe a way to display the variable name in the TextField instead of the value? or maybe a different data structure to keep both the name and the value of the variable?
Thanks in advance!