title: I need to print Null if there are no unique elements in an Array list
body: <p>I need a program that prints only the unique elements of an Array, OR, if there are no unique elements, it prints &quot;Null&quot;.
  My code already can find the unique elements and print it, but it's printing Null for each repeated ones too. I need to print just one &quot;Null&quot; if there are no unique numbers, or just the unique elements (which is working already for that).
  The example below, it should print 3 (the non repeated element), and if you put another 3 in the list, should print Null one time only (which I can't figure out how).
  I appreciate the help in advance!</p>
  <pre><code>public static void main(String[] args) {
  
          int IDs[] = { 1, 2, 3, 2, 2, 1, 5, 5 };
  
          int items = IDs.length;
  
          uniqueIDs(IDs, items);
  
      }
  
      static void uniqueIDs(int IDs[], int items) {
  
          Map&lt;Integer, Integer&gt; hash = new HashMap&lt;&gt;();
  
          for (int i = 0; i &lt; items; i++) {
  
              if (hash.containsKey(IDs[i])) {
  
                  hash.put(IDs[i], hash.get(IDs[i]) + 1);
  
              }
  
              else {
  
                  hash.put(IDs[i], 1);
              }
          }
  
          for (Map.Entry&lt;Integer, Integer&gt; uniqueIDs : hash.entrySet())
  
              if (uniqueIDs.getValue() == 1)
  
                  System.out.print(uniqueIDs.getKey() + &quot;\n&quot;);
          
              else {
                  System.out.println(&quot;null&quot;);
              }
      }
  }
  
  </code></pre>