Java 8 Tutorials
This page will cover java 8 tutorials with examples. Lambda expressions are one of the important features included in java 8. Lambda Expressions are used to write concise code. Java 8 has introduced stream API that supports functional-style operations on streams of elements. Java 8 streams can be computed in parallel and sequential way. Sequential computation is performed one by one in an order. In parallel processing computations are processed simultaneously. There is many other new API such as time, collectors, completable future etc. Now find java 8 examples one by one.
Java 8 Concat Streams, Lists, Sets, Arrays Example
On this page we will provide Java 8 concat Streams, Lists, Sets, Arrays example.
method to concatenate two streams and will return a stream.
Java 8 Distinct Example
On this page we will provide Java 8 Stream
returns a stream consisting of distinct elements of that stream.
Java 8 Stream Tutorial with Example
This page will walk through java 8 Stream tutorial with example. Java 8 has introduced a package java.util.stream that consists the classes that supports functional-style operations on streams of elements.
Java 8 Stream sorted() Example
On this page we will provide java 8 Stream sorted() example. We can sort the stream in natural ordering as well as ordering provided by Comparator.
Java 8 Stream map() Example
On this page we will provide java 8 Stream map() example. It returns a Stream instance processed by a given Function.
Java 8 Stream filter() Example
On this page we will provide java 8 Stream filter() example. It is an intermediate operation and can be used with reduce(), collect(), map() etc.
Java 8 Stream collect() Example
On this page we will provide java 8 Stream collect() example. This method performs mutable reduction operation on the stream elements.
Java 8 Stream reduce() Example
On this page we will provide java 8 Stream reduce() example. It is used to get the sum of numbers stored in List, Array etc.
Java 8 Convert List to Map using Collectors.toMap() Example
On this page we will provide java 8 convert List to Map using Collectors.toMap() example. Using lambda expression, we can convert List to Map in a single line.
Java 8 Convert Map to List using Collectors.toList() Example
On this page we will provide java 8 convert Map to List using Collectors.toList() example. A Map has key and value and we can get all keys and values as List.
Java 8 BigDecimal Sum Example
On this page we will provide java 8 BigDecimal sum example. We will use lambda expression for summation of List, Map and Array of BigDecimal.
Java 8 Sum: Array, Map and List Collection Example using reduce() and collect() Method
On this page we will provide Java 8 sum of values of Array, Map and List collection example using reduce() and collect() method. There are various ways to calculate the sum of values in java 8.
Java 8 Summary Statistics Example
On this page we will provide java 8 summary statistics example. We can calculate all statistical information such as count, min, max, sum, and average in one go.
Java 8 Collectors: joining() Example
On this page we will provide java 8 Collectors joining() example. joining() method returns Collector instance. It concatenates the input elements in encounter order.
Java 8 Arrays Parallel Prefix Example
On this page we will provide java 8 Arrays parallel prefix example. Arrays.parallelPrefix() updates the array on the basis of given operator.
Java 8 Arrays Parallel Sort Example
On this page we will provide Java 8 Arrays parallel Sort Example. Java 8 has introduced a new method parallelSort() in Arrays class.
Java 8 Stream flatMapToInt, flatMapToLong and flatMapToDouble Example
On this page we will provide Java 8 Stream flatMapToInt, flatMapToLong and flatMapToDouble example. flatMapToInt is used for int data.
Java 8 flatMap Example
On this page we will provide java 8 flatMap example. We will discuss here Stream.flatMap and Optional.flatMap() method.
Java 8 Runnable and Callable Lambda Example with Argument
On this page we will provide Java 8 Runnable and Callable lambda example with argument. In java 8 Runnable and Callable both interface have been annotated by @FunctionalInterface.
Java 8 List Example with forEach(), removeIf(), replaceAll() and sort()
On this page we will provide java 8 List example with forEach() , removeIf(), replaceAll() and sort(). forEach() method in the List has been inherited from java.lang.Iterable.
Java 8 Reflection Access to Parameter Names of Method and Constructor with Maven, Gradle and Eclipse using "-parameters" Compiler Argument
This page will walk through java 8 reflection access to parameter names of method and constructor with maven, gradle and eclipse using "-parameters" Compiler Argument.
Java 8 IntStream, LongStream and DoubleStream Example
In this page we are providing the example of Java 8 IntStream, LongStream and DoubleStream. IntStream, LongStream and DoubleStream are the specialization of primitive int stream, primitive.
Java 8 Random and SecureRandom Changes Example
In java 8, some new methods has been added in Random and SecureRandom classes. These methods are like ints, longs and doubles. They return IntStream, LongStream and DoubleStream respectively.
Java 8 CompletableFuture Example
java.util.concurrent.CompletableFuture is a Future in java 8 which is the derived class of java.util.concurrent.CompletionStage. CompletableFuture can be completed.
Java 8 Collectors: reducing Example
Java 8 Collectors.reducing is used to reduce the stream element with the help of Comparator and BinaryOperator. Collectors.reducing returns the Collector with Optional data.
Java 8 Comparator Changes for Lambda Expression Method Example
Java 8 has done changes in java.util.Comparator to support Lambda Expression. New Methods has been added that will use Java 8 function to define a Comparator.
Java 8 Collectors: partitioningBy Example
Java 8 Collectors.partitioningBy is a method that partitions the element of stream always in two part. It returns a Collector that stores the values in a Map.
Java 8 Collectors: groupingBy Example
groupingBy is a static method of java.util.stream.Collectors in java 8. groupingBy does the grouping of elements on the basis of any given key and returns a Collector.
Java 8 Collectors Examples
java.util.stream.Collectors is a java 8 class that implements the java.util.stream.Collector interface. Collectors has various methods to reduce and summarize elements of stream.
Java 8 Function Examples
Java 8 provides function API . These API are functional interface. We can assign it as lambda expression. Function accepts arguments, perform some processing and finally produces result.
Java 8 BooleanSupplier, IntSupplier, LongSupplier and DoubleSupplier Example
Java 8 has introduced supplier for different data type as functional interface. These are BooleanSupplier, IntSupplier, LongSupplier and DoubleSupplier classes.
Java 8 Util API: StringJoiner Example
java.util.StringJoiner has been introduced in Java 8. StringJoiner is a util method to construct a string with desired delimiter. If required we can also add prefix and suffix to the final string.
Java 8 UnaryOperator and BinaryOperator Example
Java 8 has introduced UnaryOperator and BinaryOperator that can be assigned as lambda expression. UnaryOperator and BinaryOperator are functional interface.
Java 8 Stream: forEach, forEachOrdered, peek, skip and toArray Example
This page will provide the examples of java 8 Stream forEach, forEachOrdered, peek, skip and toArray methods. Find the details of each method.
Java 8 Stream: flatMap, generate and Stream.of Example
On this page we will learn java 8 Stream.flatMap(), Stream.generate() and Stream.of() methods. These methods return stream object.
Java 8 Stream: findAny, findFirst, limit, max and min Example
On this page we will learn the use of java 8 stream findAny, findFirst, limit, max and min method example. findAny, findFirst, max and min methods return Optional instance.
Java 8 Stream: concat, count, sorted and distinct Example
On this page we will provide the examples of concat, count, sorted and distinct stream API methods of java 8. concat method is static and count, sorted and distinct methods are called.
Java 8 Stream: allMatch, anyMatch and noneMatch Example
Java 8 Stream allMatch, anyMatch and noneMatch methods are applied on stream object that matches the given Predicate and then returns boolean value.
Java 8 Stream: filter and map Example
On this page we will learn java 8 stream filter and map. These methods are intermediate operations. Filter filters a stream on the basis of a given predicate and returns stream object.
Java 8 BiConsumer, BiFunction and BiPredicate Example
On this page, we will learn java 8 BiConsumer, BiFunction and BiPredicate functional interface. All the three interface accepts two arguments. BiConsumer does not return.
Java 8 Supplier Example
java.util.function.Supplier is a functional interface in java 8. Supplier can be assigned in lambda expression. Supplier can be passed as an argument to different methods in java 8.
Java 8 Time API Example: Period, Year, YearMonth and ZonedDateTime
This page provides example of java 8 API like Period, Year, YearMonth and ZonedDateTime. These are new classes introduced in java 8. Period represents a time period.
Java 8 Optional Example | Avoid NullPointerException
java.util.Optional class has been introduced in java 8, that will avoid NullPointerException in our code. We can write our code more readable and in fewer lines because now we will not apply if else condition.
Java 8 Time API Example: MonthDay, Month, OffsetDateTime and OffsetTime
MonthDay, Month, OffsetDateTime and OffsetTime has been introduced in Java 8 in time API. MonthDay represents the combination of month and day. Month is an enum.
Java 8 DateTimeFormatter and DateTimeFormatterBuilder Example
Java 8 has provided DateTimeFormatter and DateTimeFormatterBuilder to play with formatting date, time or both in different ways. DateTimeFormatter has in-built formats.
Java 8 Time API Example: LocalTime, LocalDate and LocalDateTime
Java 8 time API has introduced the API to represent local time by LocalTime that does not know date and time zone, LocalDate that does not know time and time zone and LocalDateTime represents.
Java 8 Time API Example: DayOfWeek, Duration and Instant
In this page we will see the example of DayOfWeek, Duration and Instant java 8 time API. DayOfWeek represents the DAY name of the week. Duration is time amount that will be represented as a class.
Java 8 Internal Iteration: External vs. Internal Iteration
Java 8 has introduced internal iteration. forEach can iterate the collection internally. Before java 8, there was no such way to iterate list internally.
Parallel and Sequential Stream in Java 8 Collection
Java 8 Collection has been enriched by stream methods. These methods are stream() and parallelStream() which are default methods and have been written in Collection interface.
Java 8 Consumer Interface and forEach Loop
In this page we will learn Consumer functional Interface and forEach loop introduced in java 8. Consumer functional interface is used as a lambda expression assignment.
Java 8 Predicate Example
java.util.function.Predicate is a functional interface introduced in java 8. Predicate is used for assigning a lambda expression. The functional interface is test(T t) which returns Boolean value.
Java 8 Default and Static Method in Interface
Java 8 has introduced default method as well as static method that can be defined in interface. Default method is a normal java method but starts with default keyword.
Functional Interface in Java 8
Java 8 has introduced the concept of functional interface. Functional interface is nothing but a simple java interface containing only one method. In the old style functional interface.
Function.apply in Java 8
java.util.function.Function is an interface and has been introduced in java 8. Function is a functional interface. So it can be used to accept lambda expression. Function accepts one argument and returns the result.
Lambda Expressions Java 8 Example
Lambda expressions are one of the important features included in java 8. Lambda Expressions are used to write concise code for that interface which consist one method i.e. functional interface.