Welcome to the World of Online Learning:
Hello Friends “This blog helps you to learn Java programming concepts. You can learn Java language at your own speed and time. One can learn concepts of Java language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

Write a Java Program to Calculate the difference between two sets
PROGRAM: Java Program to Calculate the difference between two sets
/*Java Program to Calculate the difference between two sets*/
1: Calculate the difference between two sets
import java.util.HashSet;
import java.util.Set;
class Main {
public static void main(String[] args) {
// create first set
Set<Integer> numbers = new HashSet<>();
numbers.add(1);
numbers.add(2);
numbers.add(3);
numbers.add(4);
System.out.println(“Numbers: ” + numbers);
// create second set
Set<Integer> primeNumbers = new HashSet<>();
primeNumbers.add(2);
primeNumbers.add(3);
System.out.println(“Prime Numbers: ” + primeNumbers);
// Difference between HashSet1 and HashSet2
numbers.removeAll(primeNumbers);
System.out.println(“Numbers without prime numbers: ” + numbers);
}
}