Giter Club home page Giter Club logo

java_in_examples's Introduction

This is collection of java code examples, best practice and useful article and link for Java

Java code examples and best practice

You can find following code examples:

Java Collections and Stream Api in Article

I. Stream API

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

More examples this

java_in_examples's People

Contributors

vedenin avatar

Watchers

James Cloos avatar Eugene Dubrovka avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.