title: How to merge two streams in Java?
body: <p>Suppose we have two streams as follows:</p>
  
  <pre><code>IntStream stream1 = Arrays.stream(new int[] {13, 1, 3, 5, 7, 9});
  IntStream stream2 = Arrays.stream(new int[] {1, 2, 6, 14, 8, 10, 12});
  stream1.merge(stream2); // some method which is used to merge two streams.
  </code></pre>
  
  <p>Is there any convenient way to merge the two streams to [13, 1, 2, 3, 5, 6, 7, 8, 9, 10, 12, 14] using the Java 8 stream API (the order doesn't matter). Or can we only handle one stream at the same time?</p>
  
  <p>Furthermore, if the two streams are object streams, how is it possible to keep only distinct objects, without overriding the <code>equals()</code> and <code>hashCode()</code> methods? For example:</p>
  
  <pre><code>public class Student {
  
      private String no;
  
      private String name;
  }
  
  Student s1 = new Student("1", "May");
  Student s2 = new Student("2", "Bob");
  Student s3 = new Student("1", "Marry");
  
  Stream&lt;Student&gt; stream1 = Stream.of(s1, s2);
  Stream&lt;Student&gt; stream2 = Stream.of(s2, s3);
  stream1.merge(stream2);  // should return Student{no='1', name='May'} Student{no='2', name='Bob'}
  </code></pre>
  
  <p>We consider two students the same when their <code>no</code> is the same and regardless of the <code>name</code> (so May and Marry are the same person because their numbers are both "1").</p>
  
  <p>I've found the <code>distinct()</code> method, but this method is based on <code>Object#equals()</code>. If we are not allowed to overwrite the <code>equals()</code> method, how can we merge <code>stream1</code> and <code>stream2</code> to one stream which has no duplicate items?</p>