title: Java8 Streams - Remove Duplicates With Stream Distinct
body: <p>I have a stream such as:</p>
  
  <pre><code>Arrays.stream(new String[]{"matt", "jason", "michael"});
  </code></pre>
  
  <p>I would like to remove names that begin with the same letter so that only one name (doesn't matter which) beginning with that letter is left.</p>
  
  <p>I'm trying to understand how the <a href="https://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html#distinct--" rel="noreferrer"><code>distinct()</code></a> method works.  I read in the documentation that it's based on the "equals" method of an object.  However, when I try wrapping the String, I notice that the equals method is never called and nothing is removed.  Is there something I'm missing here?</p>
  
  <p>Wrapper Class:</p>
  
  <pre><code>static class Wrp {
      String test;
      Wrp(String s){
          this.test = s;
      }
      @Override
      public boolean equals(Object other){
          return this.test.charAt(0) == ((Wrp) other).test.charAt(0);
      }
  }
  </code></pre>
  
  <p>And some simple code:</p>
  
  <pre><code>public static void main(String[] args) {
      Arrays.stream(new String[]{"matt", "jason", "michael"})
      .map(Wrp::new)
      .distinct()
      .map(wrp -&gt; wrp.test)
      .forEach(System.out::println);
  }
  </code></pre>