title: How to sort with condition in JAVA8 lambda
body: <p>I'm using Java-8 lambda to sort a list.</p>
  
  <p>Here is list of</p>
  
  <pre><code>[(t1, tester1), (t4, tester4), (t3, tester3), (t2, tester2)]
  </code></pre>
  
  <p>after sort</p>
  
  <pre><code>[(t2, tester2), (t1, tester1), (t3, tester3), (t4, tester4)]
  </code></pre>
  
  <p>I want to get result as above</p>
  
  <pre><code>String specialId = 't2'
  
  List&lt;Test&gt; list = new ArrayList&lt;&gt;();
  
  Test test1 = new Test();
  test1.setId = "t1"
  test1.setName = "tester1"
  list.add(test1)
  
  Test test2 = new Test();
  test2.setId = "t4"
  test2.setName = "tester4"
  list.add(test2)
  
  Test test3 = new Test();
  test3.setId = "t3"
  test3.setName = "tester3"
  list.add(test3)
  
  Test test4 = new Test();
  test4.setId = "t2"
  test4.setName = "tester2"
  list.add(test4)
  
  Stream&lt;Test&gt; s1 = list.stream.filter(t -&gt; t.getId.equals(specialId));
  Stream&lt;Test&gt; s2 = list.stream.filter(t -&gt; !t.getId.equals(specialId))
                      .sorted(Comparator.comparing(Test::getName));
  
  Stream&lt;Test&gt; s = Stream.concat(s1, s2);
  
  List&lt;Test&gt; result = s.collect(Collectors.toList());
  </code></pre>
  
  <p>I am getting the expected result. But I want use stream only once.
  How can I sort it?</p>