I've got a data source that I pull a whole list of words out of. I just need to count how many times each word comes out and then return the top 10 or so. Easy? Apparently not.
My first thought was to throw everything into some sort of hash or collection, with the word string as the key and the number of times it has appeared as the value. However, there is no class like that which lets you sort by value to return the highest 10. The only way I could think of doing it is throwing the name/value pairs into a hashtable, going through each one and then adding the index of the hashtable key into an arraylist comparing it's value with every existing entry in the arraylist to see where it should go. I'd then end up with an arraylist containig the sorted indexes of the keys in the hashtable. A fairly bad way of doing it.
Any ideas?
My first thought was to throw everything into some sort of hash or collection, with the word string as the key and the number of times it has appeared as the value. However, there is no class like that which lets you sort by value to return the highest 10. The only way I could think of doing it is throwing the name/value pairs into a hashtable, going through each one and then adding the index of the hashtable key into an arraylist comparing it's value with every existing entry in the arraylist to see where it should go. I'd then end up with an arraylist containig the sorted indexes of the keys in the hashtable. A fairly bad way of doing it.
Any ideas?