Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

set intersection java

set1.retainAll(set2);
Comment

Java Intersection of Sets

import java.util.LinkedHashSet;

class Main {
    public static void main(String[] args) {
        LinkedHashSet<Integer> primeNumbers = new LinkedHashSet<>();
        primeNumbers.add(2);
        primeNumbers.add(3);
        System.out.println("LinkedHashSet1: " + primeNumbers);

        LinkedHashSet<Integer> evenNumbers = new LinkedHashSet<>();
        evenNumbers.add(2);
        evenNumbers.add(4);
        System.out.println("LinkedHashSet2: " + evenNumbers);

        // Intersection of two sets
        evenNumbers.retainAll(primeNumbers);
        System.out.println("Intersection is: " + evenNumbers);
    }
}
Comment

Java Intersection of Sets

import java.util.TreeSet;;
class Main {
    public static void main(String[] args) {
        TreeSet<Integer> evenNumbers = new TreeSet<>();
        evenNumbers.add(2);
        evenNumbers.add(4);
        System.out.println("TreeSet1: " + evenNumbers);

        TreeSet<Integer> numbers = new TreeSet<>();
        numbers.add(1);
        numbers.add(2);
        numbers.add(3);
        System.out.println("TreeSet2: " + numbers);

        // Intersection of two sets
        numbers.retainAll(evenNumbers);
        System.out.println("Intersection is: " + numbers);
    }
}
Comment

Java Intersection of Sets

import java.util.HashSet;

class Main {
    public static void main(String[] args) {
        HashSet<Integer> primeNumbers = new HashSet<>();
        primeNumbers.add(2);
        primeNumbers.add(3);
        System.out.println("HashSet1: " + primeNumbers);

        HashSet<Integer> evenNumbers = new HashSet<>();
        evenNumbers.add(2);
        evenNumbers.add(4);
        System.out.println("HashSet2: " + evenNumbers);

        // Intersection of two sets
        evenNumbers.retainAll(primeNumbers);
        System.out.println("Intersection is: " + evenNumbers);
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: toSet 
Java :: aws s3 client in java 
Java :: Java Multiple element Annotations 
Java :: lighting strike solved 
Java :: jumping sequence java boolean values 
Java :: jdbc api in java 
Java :: rgb code from java color 
Java :: hash tree in java 
Java :: Add an element at a specified position in an ArrayList 
Java :: component spring 
Java :: java binary search tree 
Java :: Caused by: android.view.InflateException: Binary XML file line 
Java :: import class java 
Java :: java lambda 
Java :: multiple return values in function java 
Java :: find number of weeks between two dates in java 
Java :: Java if (if-then) Statement 
Java :: calculate standard deviation in java 
Java :: imperative programming paradigm example 
Java :: java 8 function supplier consumer 
Java :: save text in edditext java 
Java :: declare variable java 
Sql :: how to get the size of the database in postgresql 
Sql :: insert column after column mysql 
Sql :: forgot mysql root password stackoverflow 
Sql :: list all triggers in sql server 
Sql :: mysql return 0 if null 
Sql :: Query the list of CITY names ending with vowels (a, e, i, o, u) from STATION. Your result cannot contain duplicates. Input Format The STATION table is described as follows: 
Sql :: liquibase alter column type / length 
Sql :: sql dateadd hours 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =