# Getting intersection of sets in Julia – intersect() and intersect!() Methods

• Last Updated : 24 Feb, 2021

The intersect() is an inbuilt function in julia which is used to construct the intersection of the specified sets.

Syntax:

` intersect(s, itrs...)`

Parameters:

• s: Specified first set.
• itrs: Specified second set.

Returns: It returns the constructed intersection of the specified sets.

Example:

## Python

 `# Julia program to illustrate``# the use of intersect() method`` ` `# Getting the intersection of sets.``println(intersect([``1``, ``4``, ``6``], [``1``, ``3``, ``5``]))``println(intersect([``1``, ``2``, ``3``, ``4``], [``0``, ``1``, ``2``, ``3``]))``println(intersect(``Set``([``2``, ``3``]), BitSet([``3``, ``4``])))`

Output:

#### intersect!()

The intersect!() is an inbuilt function in julia which is used to intersect all passed in sets and overwrite s with the result.

Syntax:

`intersect!(s::Union{AbstractSet, AbstractVector}, itrs...)`

Parameters:

• s: Specified set.
• itrs: Specified iterator.

Returns: It returns the elements which intersect all passed in sets.

Example:

## Python

 `# Julia program to illustrate``# the use of intersect !() method`` ` `# Getting the elements which``# intersect all passed in sets.``println(intersect !([``1``, ``4``, ``6``], [``1``, ``3``, ``5``]))``println(intersect !([``1``, ``2``, ``3``, ``4``], [``0``, ``1``, ``2``, ``3``]))``println(intersect !(``Set``([``2``, ``3``]), BitSet([``3``, ``4``])))`

Output:

My Personal Notes arrow_drop_up