com.example.mistakes.expression._11_IgnoredReturnValue.Ex6

🚀 com.example.mistakes.expression._11_IgnoredReturnValue.Ex6

Question fetched from API endpoint api/expression/11/6

API Response

GET /api/expression/11/6
{
  "result": [
    {
      "message": "com.example.mistakes.expression._11_IgnoredReturnValue.Ex6",
      "before": "    List<String> before(List<String> stringList) {\n      stringList.stream().sorted();\n      stringList.stream().filter(str -> !str.isEmpty());\n      return stringList;\n    }\n",
      "after": "    List<String> after(List<String> stringList) {\n      // if given stringList is mutable\n      if (stringList instanceof ArrayList) {\n        stringList.removeIf(String::isEmpty);\n        stringList.sort(null);\n        return stringList;\n      }\n",
      "chapter": 2,
      "id": "2_11_6",
      "className": "Ex6",
      "path": "file:///home/runner/work/100_java_mistakes/100_java_mistakes/back/src/main/java/com/example/mistakes/expression/_11_IgnoredReturnValue.java"
    }
  ],
  "length": 1
}

before

before
List<String> before(List<String> stringList) {
  stringList.stream().sorted();
  stringList.stream().filter(str -> !str.isEmpty());
  return stringList;
}

after

after
List<String> after(List<String> stringList) {
  // if given stringList is mutable
  if (stringList instanceof ArrayList) {
    stringList.removeIf(String::isEmpty);
    stringList.sort(null);
    return stringList;
  }