Hello, I am trying to return the union of two ArraySet Strings as a third; however, the compiler is complaining:

found : jss2.SetADT<java.lang.String>
required: jss2.ArraySet<java.lang.String>
union = one.union(two);

I was thinking I could pass an ArraySet<String> as the parameter but unfortunetly I am stuck here. Any suggestions on how to get this one.union(two) assigned to un? I've attatched the jss2 package to the thread.

import jss2.*;
import java.util.*;


public class Hw8p2 {
	 
	 public static void main (String[] args) { 
	
	 ArraySet<String> one = new ArraySet<String>();
	 ArraySet<String> two = new ArraySet<String>();
	 ArraySet<String> un = new ArraySet<String>();
	 String s_one_1 = "one";
	 String s_one_2 = "two";
	 String s_one_3 = "three";
	 one.add(s_one_1);
	 one.add(s_one_2);
	 one.add(s_one_3);
	 String s_two_1 = "four";
	 String s_two_2 = "five";
	 String s_two_3 = "six";
	 two.add(s_two_1);
	 two.add(s_two_2);
	 two.add(s_two_3);
	 System.out.println(one);
	 System.out.println(two);
	 
          un = one.union(two);
 
	 }
}

You can cast the result to the appropriate type:

un = (ArraySet<String>)one.union(two);

many thanks, i was casting all wrong before with un = one.union((ArraySet<String>)two);

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.