Last active
February 22, 2018 03:29
-
-
Save A-pZ/0288f820cbd76840c7a90115663d4499 to your computer and use it in GitHub Desktop.
「Forループの代わりにIntStream使いましょう」の話
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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