 <p>Create a Map of your words and occurencies. </p> <pre><code>import java.util.*; public class TestDummy { public static void main(String args[]) { String arr[] = { "lady", "bird", "is", "bird", "lady", "cook" }; Map&lt;String, Integer&gt; dictionary = new TreeMap&lt;&gt;(); int len = arr.length; System.out.println("Size " + len); for (int i = 0; i &lt; len; i++) { if (dictionary.containsKey(arr[i])) { dictionary.put(arr[i], dictionary.get(arr[i]) + 1); System.out.format("Duplicate %s%n", arr[i]); } else { dictionary.put(arr[i], 1); } } } } **Output** Size 6 Duplicate bird Duplicate lady </code></pre>