Yes, week1/test1.java does give duplicates. Point it at this website to see.
A difference between a list and a set is that lists contain duplicates but set don't. Study week2/test2.java. Notice the use of HashSet. Look up HashSet.
java setPlay asda asasdaqweqewill output:
[w, d, e, s, q, a] [d,s,a] [](The order may be different)
Hint:
class setPlay { static HashSet <Character> stringToSet(String s) { HashSet <Character> s1= new HashSet(); for (int i=0;i<s.length();i++) { //add the ith element of s to the set s1 } return s1; } public static void main(String [] args) { HashSet <Character> a1 = stringToSet(args[0]); HashSet <Character> a2 = stringToSet(args[1]); //set b to the union of a1 and a2. //set c to the intersection of a1 and a2. //set d to the difference of a1 and a2. System.out.println(b);System.out.println(c);System.out.println(d); } }Upload your assignment to directory IS52013B-assignments-2010-11 or to IS52014B-assignments-2010-11 depending on your course. Watch video (Help with Easy Assignment 2)
s.danicic@gold.ac.uk