title: java 8 stream.sorted with comparator in sets
body: <p><strong>I have a set to sort (with Comparators) and I dont know which version to choose:</strong></p>
  
  <p><strong>version 1:</strong></p>
  
  <pre><code>public static void sort(Set&lt;User&gt; users) {
      users = users.stream()
      .sorted(sort_gender.thenComparing(sort_age))
      .collect(Collectors.toCollection(LinkedHashSet::new));
  }
  </code></pre>
  
  <p><strong>version 2:</strong></p>
  
  <pre><code>public static Set&lt;User&gt; sort(Set&lt;User&gt; users) {
      return users.stream()
      .sorted(sort_gender.thenComparing(sort_age))
      .collect(Collectors.toCollection(LinkedHashSet::new));
  }
  </code></pre>
  
  <p><strong>version 3:</strong></p>
  
  <pre><code>public static void sort(Set&lt;User&gt; users) {
      users.stream()
      .sorted(sort_gender.thenComparing(sort_age))
      .collect(Collectors.toSet());
  }
  </code></pre>
  
  <p><strong>version 4</strong></p>
  
  <pre><code>public static List&lt;User&gt; sort(Set&lt;User&gt; users){
  
  List&lt;User&gt; list = new ArrayList&lt;&gt;(users);
  list.sort(sort_gender.thenComparing(sort_age));
  return list;
  }
  </code></pre>
  
  <p>All versions sorts a set and returns the sorted set. I know, only linkedHashSet can preserve ordering. </p>
  
  <p><strong>Which one should I choose</strong>, I only want to sort the input properties users and return it, so is version 1 the best for that case? (For all cases, I want the references of input users be the same as for output users.)</p>
  
  <p><strong>EDIT: I think, I will choose version 4.</strong> </p>