You can find following code examples:
-
I. Compare collections in Apache, Guava, Gs Collection and JDK analog
-
II. Compare operations with collections in Apache, Guava, Gs Collection and JDK
- 1. Operations for comparison collections (containsAll, containsAny, intersect, difference, symmetric difference, union)
- 2. Operations for searching in collections (count, getFirst, getLast, getSingle, getMax, getMin, binarySearch, search, getByIndex, select)
- 3. Create collections (ArrayList, HashSet, HashMap)
- 4. Transform collections (sort, remove, retain, transform, changeAll)
-
IV. Examples of Dependency injections in Dagger, Spring and Guice
-
V. Examples of Natural Language Processing using OpenNLP, Stanford NLP amd so on
Way to create stream | Template | Example |
---|
- Classic: Create stream from collection | collection.stream() | Collection collection = Arrays.asList("a1", "a2", "a3");
Stream streamFromCollection = collection.stream(); - Create stream from values | Stream.of(value1,… ,valueN) | Stream streamFromValues = Stream.of("a1", "a2", "a3");
- Create stream from array | Arrays.stream(array) | String[] array = {"a1","a2","a3"};
Stream streamFromArrays = Arrays.stream(array); - Create stream from part of array | Arrays.stream(array, start, end) | String[] array = {"a1","a2","a3"};
Stream streamFromArrays = Arrays.stream(array, 1, 2); - Create stream from file (every row from file become element of stream) | Files.lines(file_path) | Stream streamFromFiles = Files.lines(Paths.get("file.txt"));
- Create stream from stirng (every char become element of stream) | "string".chars() | IntStream streamFromString = "123".chars();
- Using Stream.builder | Stream.builder().add(...)....build() | Stream.builder().add("a1").add("a2").add("a3").build();
- Create parallel stream from collection | collection.parallelStream() | Stream stream = collection.parallelStream();
- Create infinive strean using Stream.iterate | Stream.iterate(init_value, generate_expression) | Stream streamFromIterate = Stream.iterate(1, n -> n + 1);
- Create infinive strean using Stream.generate | Stream.generate(generate_expression) | Stream streamFromGenerate = Stream.generate(() -> "a1");
- Create stream from path | Files.list(file_path) | Stream streamFromPath = Files.list(Paths.get(""));
- Create stream from finding files | Files.find(file_path, max_depth, mathcher) | Stream streamFromFind = Files.find(Paths.get(""), 10, (p,a) -> true);
- Create stream from files tree | Files.walk(file_path) | Stream streamFromFileTree = Files.walk(Paths.get(""));
- Create stream from all entities of jar file | new JarFile(jar_file).stream() | …
- Create stream from all entities of zip file | new ZipFile(zip_file).stream() | …
- Create stream from iterator | StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, 0), false) | ...
- Create stream from iterable | StreamSupport.stream(iterable.spliterator(), false) | …
- Create infinive stream from iterator | Stream.generate(iterator::next) | …
- Create empty stream | Stream.empty() | Stream streamEmpty = Stream.empty();
- Create stream from Pattern | Pattern.compile(reg_exp).splitAsStream(string) | Stream streamFromPattern = Pattern.compile(":").splitAsStream("a1:a2:a3");
- Create stream from BufferedReader | bufferedReader.lines() | Stream streamFromBufferedReader = bufferedReader.lines();
- Create stream from Enum | EnumSet.allOf(MyEnum.class).stream() | Stream streamFromEnum = EnumSet.allOf(MyEnum.class).stream();
More examples this