title: Return List<Integer> from Method in Java 8?
body: <p>I have the following method (see below). The code is working but I got сomments that there is a lot of repeating and that I should use <code>IntStream</code>.</p>
  
  <p>Could you specify how to better optimize the code? Thanks in advance.</p>
  
  <pre><code>public static List&lt;Integer&gt; oddOrEven(List&lt;Integer&gt; integers) {
      long sum = integers.stream().mapToInt(i -&gt;i).summaryStatistics().getSum();
      if (sum % 2 == 0) {
          return integers.stream().filter(x -&gt; x % 2==0).distinct().collect(Collectors.toList());
      } else if (sum % 2 != 0) {
          return integers.stream().filter(x -&gt; x % 2 != 0).distinct().collect(Collectors.toList());
      }
      return null;
  }
  </code></pre>