Skip to content

Commit 48361a8

Browse files
author
vvedenin
committed
Add readme.md to other tests
1 parent 43b3a97 commit 48361a8

File tree

2 files changed

+30
-0
lines changed
  • helloworlds
    • 1.6-usefull-libraries/functional_programming/jdk_stream_api
    • 5.0-other-examples/src/main/java/other_examples

2 files changed

+30
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
###### I. All way to create Stream in Java 8
2+
3+
Way to create stream | Template | Example
4+
------------- | ------------- | -------------
5+
1. Classic: Create stream from collection | collection.stream() | Collection<String> collection = Arrays.asList("a1", "a2", "a3"); <br/> Stream<String> streamFromCollection = collection.stream();
6+
2. Create stream from values | Stream.of(value1,… ,valueN) | Stream<String> streamFromValues = Stream.of("a1", "a2", "a3");
7+
3. Create stream from array | Arrays.stream(array) | String[] array = {"a1","a2","a3"}; <br/> Stream<String> streamFromArrays = Arrays.stream(array);
8+
3. Create stream from part of array | Arrays.stream(array, start, end) | String[] array = {"a1","a2","a3"};<br/> Stream<String> streamFromArrays = Arrays.stream(array, 1, 2);
9+
4. Create stream from file (every row from file become element of stream) | Files.lines(file_path) | Stream<String> streamFromFiles = Files.lines(Paths.get("file.txt"));
10+
5. Create stream from stirng (every char become element of stream) | "string".chars() | IntStream streamFromString = "123".chars();
11+
6. Using Stream.builder | Stream.builder().add(...)....build() | Stream.builder().add("a1").add("a2").add("a3").build();
12+
7. Create parallel stream from collection | collection.parallelStream() | Stream<String> stream = collection.parallelStream();
13+
8. Create infinive strean using Stream.iterate | Stream.iterate(init_value, generate_expression) | Stream<Integer> streamFromIterate = Stream.iterate(1, n -> n 1);
14+
9. Create infinive strean using Stream.generate | Stream.generate(generate_expression) | Stream<String> streamFromGenerate = Stream.generate(() -> "a1");
15+
10. Create stream from path | Files.list(file_path) | Stream<Path> streamFromPath = Files.list(Paths.get(""));
16+
11. Create stream from finding files | Files.find(file_path, max_depth, mathcher) | Stream<Path> streamFromFind = Files.find(Paths.get(""), 10, (p,a) -> true);
17+
11. Create stream from files tree | Files.walk(file_path) | Stream<Path> streamFromFileTree = Files.walk(Paths.get(""));
18+
12. Create stream from all entities of jar file | new JarFile(jar_file).stream() | …
19+
13. Create stream from all entities of zip file | new ZipFile(zip_file).stream() | …
20+
14. Create stream from iterator | StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, 0), false) | ...
21+
15. Create stream from iterable | StreamSupport.stream(iterable.spliterator(), false) | …
22+
16. Create infinive stream from iterator | Stream.generate(iterator::next) | …
23+
17. Create empty stream | Stream.empty() | Stream<String> streamEmpty = Stream.empty();
24+
18. Create stream from Pattern | Pattern.compile(reg_exp).splitAsStream(string) | Stream<String> streamFromPattern = Pattern.compile(":").splitAsStream("a1:a2:a3");
25+
19. Create stream from BufferedReader | bufferedReader.lines() | Stream<String> streamFromBufferedReader = bufferedReader.lines();
26+
20. Create stream from Enum | EnumSet.allOf(MyEnum.class).stream() | Stream<MyEnum> streamFromEnum = EnumSet.allOf(MyEnum.class).stream();
27+

helloworlds/5.0-other-examples/src/main/java/other_examples/readme.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
### Other examples
2+
This section has examples for JDK or several libraries or framework in one time
3+
14
#### **I. Ways to convert an InputStream to a String:**
25

36
From this [StackOverflow post](http://stackoverflow.com/questions/309424/read-convert-an-inputstream-to-a-string/35446009#35446009):

0 commit comments

Comments
 (0)