Suppose, you have an array.
- Apple
- Apple
- Banana
- Mushroom
- Carrot
- Carrot
- Mushroom
- Pumpkin
- Mushroom
- Carrot
- Apple
- Durian
- Pitaya
- Peach
You want to count the repeated elements contained in this array and count the number of times they appear.
Solution:
use Dictionary object. when an element is first found, add it to the Key. If it appears again, increase the Value.