Skip to content

Instantly share code, notes, and snippets.

@A-pZ
Last active February 22, 2018 03:29
Show Gist options
  • Save A-pZ/0288f820cbd76840c7a90115663d4499 to your computer and use it in GitHub Desktop.
Save A-pZ/0288f820cbd76840c7a90115663d4499 to your computer and use it in GitHub Desktop.
「Forループの代わりにIntStream使いましょう」の話
public class IntStreamSample {
private int parseLength = 3;
public List<String> parse(String target) {
if (target == null || target.isEmpty()) {
return Collections.emptyList();
}
final String parseTarget = " " + target + " ";
return
IntStream.rangeClosed(0, parseTarget.length()-parseLength)
.mapToObj(i -> parseTarget.substring(i, i+parseLength))
.collect(Collectors.toList());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment