title: Bubble sort in functional style Java 8
body: <p>How would you implement the following Bubble Sort algorithm in a functional (Java 8) way?</p>
  <pre class="lang-java prettyprint-override"><code>public static final &lt;T extends Comparable&lt;T&gt;&gt; List&lt;T&gt; imperativeBubbleSort(List&lt;T&gt; list) {
      int len = list == null ? 0 : list.size();
      for (int j = len - 1; j &gt; 0; j--) {
          for (int k = 0; k &lt; j; k++) {
              if (list.get(k + 1).compareTo(list.get(k)) &lt; 0) {
                  list.add(k, list.remove(k + 1));
              }
          }
      }
      return list;
  }
  </code></pre>