## Free Data Structures and Algorithms Course

### How to perform operations of Union and Intersection on two or more LinkedList in Java ?.

Program to demonstrate Union and Intersection of two LinkedList in Java

```package com.hubberspot.collections.example;

import java.util.*;
import java.io.*;

{

public static void main(String args[]) throws IOException
{

int num1, num2;

System.out.print("Enter no.of Elements in list 1:");

System.out.println("Enter Elements of list 1");

for(int i=1; i <= num1; i++)
{
System.out.print("Enter Element "+i+": ");

if(!list1.contains(element))
}

System.out.print("Enter no.of Elements in list 2:");

System.out.println("Enter Elements of list 2");

for(int i=1; i <= num2; i++)
{
System.out.print("Enter Element "+i+": ");

if(!list2.contains(element))
}

Collections.sort(list1);
Collections.sort(list2);

System.out.println("List 1:"+list1);
System.out.println("List 2:"+list2);

for(int i=0; i < list1.size(); i++)

for(int i=0; i < list2.size(); i++)
if(!list1.contains(list2.get(i)))

System.out.println("Union: "+list3);

for(int i=0; i < list1.size(); i++)