How to find the non-repeating string from the list of string
<p>There is given a list of strings out which we have to print the unique strings. Unique string is a string which is not repeated in the list of string.</p>

<pre><code>Ex li = [ram,raj,ram,dev,dev]
unique string = raj. 
</code></pre>

<p>I thought of one algorithm. </p>

<p>First sort the String array, then check the adjacent string if its equal then move forward otherwise its a unique string.
But here the time Complexity is very high for sorting the string array.</p>

<p>Can any body help me in finding the more efficient algorithm then mine algo?
Thanks in advance.</p>

<p>You could try below</p>

<pre><code>    List&lt;String&gt; names = Arrays.asList("ram", "raj", "ram", "dev", "dev");
    Map&lt;String, Long&gt; nameCount = names.stream().collect(Collectors.groupingBy(s -&gt; s, Collectors.counting()));
    List&lt;String&gt; unique = nameCount.entrySet().stream().filter(e -&gt; e.getValue() == 1L).map(Map.Entry::getKey).collect(Collectors.toList());
    System.out.println(nameCount);
    System.out.println(unique);
</code></pre>

<p>ouput</p>

<pre><code>{dev=2, raj=1, ram=2}
[raj]
</code></pre>

<p><strong>EDIT</strong></p>

<pre><code>    List&lt;String&gt; uniq = new ArrayList&lt;&gt;();
    names.stream().sorted().forEach(n -&gt; {
        if (uniq.contains(n)) {
            uniq.remove(n);
        } else {
            uniq.add(n);
        }
    });
</code></pre>

<p>Instead of list map cab be used to check contains in O(1)</p>

java python c++ string algorithm