title: Return elements that appear only once in array
body: <p>I have an array and my goal is to return unique elements. I wrote the code that sorts an array and stores unique elements in ArrayList, but instead of returning only <code>[7]</code> it returns <code>[2,5,7]</code>. Why so?</p>
  <pre><code>public static void main(String[] args) {
      ArrayList&lt;Integer&gt; list = new ArrayList&lt;&gt;();
      int [] arr = {2, 5, 14, 14, 2, 7, 5};
      Arrays.sort(arr);
      for (int i =0; i&lt;arr.length-1; i++){
          if(arr[i]!=arr[i+1]){
              list.add(arr[i]);
          }
      }
      System.out.println(list);
  }
  </code></pre>