Question Index

Write a program to remove the elements of first input which elements are matched with second input or not?.
By using one of the Set interface methods.

Input (HashSet, HashSet) Output (Boolean)
[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 5, 6] true
[Cricket, Chess, Hockey, Foot Ball], [Foot Ball, Chess, Race] true
['M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T'], ['A', 'B', 'C', 'D', 'E'] fasle
[Apple, Rose, Pink, Banana], null null

import java.util.*;
class RemoveElements
    public static void main(String s[])
        HashSet input1 = new HashSet();
        HashSet input2 = new HashSet();
        System.out.println("Are removed elements: " + areRemoved(input1, input2));


    public static Boolean areRemoved(HashSet input1, HashSet input2) {




Topic: HashSet Class In Java

Read this topic
Take test on this topic

Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App