Last active
December 20, 2020 17:21
-
-
Save hadinajafi/7e45afe7f42d4e215e2136ae37f6772c to your computer and use it in GitHub Desktop.
Overall Java 8 Streams code samples
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
// break a string into multiple substrings with RegEx | |
Stream<String> streamOfString = Pattern.compile(", ").splitAsStream("a, b, c"); | |
//creating stream of strings from array | |
String[] arr = {"a", "b", "c"}; | |
Stream<String> streamOfArray = Arrays.stream(arr); | |
// every line of text becomes an element of stream | |
Path path = Paths.get("C:\\file.txt"); | |
Stream<String> streamOfStrings = Files.lines(path); | |
Stream<String> streamWithCharset = Files.lines(path, Charset.forName("UTF-8")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment