Java | 1 Line | Streams
Approach  - One Line\n Describe your approach to solving the problem. \n###### collect method first creates a StringBuilder object, then traverses all the eleme
# Approach  - One Line\n<!-- Describe your approach to solving the problem. -->\n###### ***collect*** method first creates a StringBuilder object, then traverses all the elements in the stream and adds the first letters of these elements one by one to created object. Finally we return the object as String and it is compared to s.\n\n# Complexity\n- Time complexity: **O(n)**\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n- Space complexity: **O(n)**, because the collect function creates a new StringBuilder, then populates it and returns\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n\n# Code\n```\nclass Solution {\n    public boolean isAcronym(List<String> words, String s) {\n        \n        return s.equals(\n            words.stream()\n                .collect(StringBuilder::new, (sb, str) -> sb.append(str.charAt(0)), StringBuilder::append)\n                .toString()\n        );\n\n    }\n}\n```\n\n###### Using ***"StringBuilder::new"*** is no different than ***"new StringBuilder()"***, it only makes the code shorter and more readable. For more, you can search as **method reference**.\n\n###### *The combiner parameter of the collect method does not work because it is not a parallel stream. So no unnecessary additional action was taken.*\n\n```\nbool shouldYouUpvote(){ return (I helped == true) ? upvote : nothing; }\n```
['Java']