Using Java programming,
import java.lang.*;
import java.util.*;
//list class
class name_list{
//declaring the empty arraylist to add inputs
strings
ArrayList<String> first;
ArrayList<String> second;
int n=0,m=0;
//two parameter constructer
public name_list(int n,int m){
this.n=n;
this.m=m;
//initiating the two array
lists
first = new
ArrayList<String>(n+m);
second = new
ArrayList<String>(m);
}
//adding the strings to first arraylist
public void add_elements_first(String value){
first.add(value);
}
//adding the strings to second arraylist
public void add_elements_second(String value){
second.add(value);
}
//method to find the union of two arralsit
public ArrayList<String> union(){
//initializing the empty arraylist
to store the union of wo arrays
ArrayList<String> temp = new
ArrayList<String>(n+m);
//initalizing the iterator to loop
through the arraylist
Iterator<String> itr1 =
first.iterator();
while(itr1.hasNext()){
temp.add(itr1.next());
//adding the
elements to arraylist
}
Iterator<String> itr2 =
second.iterator();
//finding the union
while(itr2.hasNext()){
String var
=itr2.next();
if(!temp.contains(var)){
temp.add(var);
}
}
// Iterator<String> temp1 =
temp.iterator();
// while(temp1.hasNext()){
//
System.out.println(temp1.next());
// }
return temp;
}
}
class driverCheck{
public static void main(String[] args) {
Scanner scan = new
Scanner(System.in);
System.out.println("Enter the size
of first queue");
int n = scan.nextInt();
System.out.println("Enter the size
of second queue");
int m = scan.nextInt();
//creating the class object
name_list obj = new
name_list(n,m);
//looping to read the arraylist
elements to first arraylist
for (int i=0;i<n ;i++ ) {
System.out.println("Enter the"+i+" value");
obj.add_elements_first(scan.next());
}
//looping to read the arraylist
elements to second arraylist
for (int i=0;i<m;i++ ) {
System.out.println("Enter the"+i+" value");
obj.add_elements_second(scan.next());
}
System.out.println("\n");
System.out.println("union");
//return array list
ArrayList<String> chk =
obj.union();
Iterator<String> chkitr =
chk.iterator();
while(chkitr.hasNext()){
System.out.println(chkitr.next());
}
}
}
Using Java programming, The Set interface in the API has the methods addAll(Collection<? exte...
The question exercises the union, intersection, and the intersection operations of two set of strings (names). For this type of problem, you need to preserve the original sets from being modified by some of the set method. You can used the clone( ) method to copy the sets or simply create another set using the same array contents as the original. You can find an example of the clone() for the LinkedHashSet set in the provided “skeleton” program (assign8_Q3.java) code...
Complete the following case study: Case study: Three implementations of contains - comparing approaches to adding functionality Set A contains Set B if every element in Set B is also in Set A. We will compare three ways to determine whether Set A contains Set B. Approach 1: Write code in the main method in a test class Add code to the main of ArraySetTester to create SetA and SetB, fill them with data and write a contains operation that...