0% found this document useful (0 votes)
27 views20 pages

Extra Topics

The document discusses several Java concepts including enums, generics, functional interfaces, lambda expressions, and streams. Enums represent a group of constants. Generics allow code reuse with different types. Functional interfaces have a single abstract method and can be used with lambda expressions. Streams provide operations on collections without modifying them.

Uploaded by

MUSTAFA ATİK
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views20 pages

Extra Topics

The document discusses several Java concepts including enums, generics, functional interfaces, lambda expressions, and streams. Enums represent a group of constants. Generics allow code reuse with different types. Functional interfaces have a single abstract method and can be used with lambda expressions. Streams provide operations on collections without modifying them.

Uploaded by

MUSTAFA ATİK
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Extra Topics

Enum

• Represents a group of constants (number of things)

• Used for containing fixed set of constants


Enum Examples
Generics

• Parameterized types

• Allows us reuse the same code with different types

• Generic types can be applied to method, class and interface


Functional Interface & lambda
Functional Interface

• There is only one abstract method in the

interface

• Effectively acts as a function

• The @FunctionalInterface annotation is

applicable (Optional)
Functional Interface

Define functional interface

Abstract method
Lambda Expression

• A function with no name and an identifier

• Can be defined in the place where they

are needed

• Expresses the instances of a functional

Interface
Syntax of Lambda Expression

(int agr1, double arg2… ) -> { Statements }

Parameters Arrow Lambda


token expression’s body

Syntax Description
Takes no argument and executes the given statement(s)
( ) -> { statements }
in lambda expression’s body
Takes argument(s) and executes the given statements in
(Parameters) -> { statements }
lambda expression’s body
Build-in Functional Interface: Predicate

• Represents a function which takes one argument (any object) and

returns boolean

Abstract method
Build-in Functional Interface: Consumer

• Represents a function which takes one argument (any object) and

does not return a value

Abstract method
Build-in Functional Interface: Function

• Represents a function which takes one argument (any object) and return a

value (any object)

Abstract method
Build-in Functional Interface: BiPredicate

• Represents a function which takes one argument (any object) and

returns boolean

Abstract method
Build-in Functional Interface: BiConsumer

• Represents a function which takes two argument (any object) and

does not return a value

Abstract method
Build-in Functional Interface: BiFunction

• Represents a function which takes two arguments (any objects) and return

a value (any object)

Abstract method
Stream API
Stream

• Stream is a sequence of elements from a data structure (Array/Collection)

• Stream takes inputs from the source (Array/Collection), but unable to

change/modify it
Stream
Stream Intermediate Operations

• After calling the stream() function from an Array/Collection to obtain stream

instance, the intermediate operations can be accessed

Method Method Methods

distinct() skip() limit()

map() filter() sorted()

peek()
Stream Intermediate Operations

• The terminal operations can be accessed through the stream instance

Method Method Methods

collect() toArray() count()

reduce() findAny() findAll()

forEach() min() max()

allMatch() anyMatch() nonMatch()

You might also like