Is this correct usage of lambdas in Java 8? -


final list<string> userids = request.getuserids(); final list<string> keys = userids.stream().map(p -> {      return removeprefix(p);  }).collect(collectors.tolist()); 

basically, every key in list of userids contains prefix "_user" want remove every key. so, invoking removeprefix function on each item of list , storing result in list called "keys"

yes it's fine although make little shorter , more readable method reference , static import:

final list<string> keys = userids.stream()                                  .map(this::removeprefix)                                  .collect(tolist()); 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

node.js - How to abort query on demand using Neo4j drivers -