-
August 10th, 2010, 02:53 PM
#1
Using Contains method in HashSet
I'm working on a project in Java, I am new to java and haven't used it much before so any help would be appreciated. I have two HashSets with elements in them. I am trying to write a method to return a boolean stating if one set contains all of the elements from another set
this is what I have so far
import java.util.HashSet;
import java.util.Iterator;
import java.util.TreeSet;
public class Specification {
public static void main(String[] args) {
// Create two sets.
HashSet s1 = new HashSet();
s1.add("r1");
s1.add("r2");
s1.add("r3");
HashSet s2 = new HashSet();
s2.add("r1");
s2.add("r2");
s2.add("r3");
s2.add("r4");
//check if s2 contains s1
public static <T> boolean isSubset(HashSet<T> s2, HashSet<T> s1); {
return s2.containsAll(s1);
I need help to rectify my contains method. Can someone tell me what's wrong with it and how I can fix it. I get errors on the static and boolean sections. I am using Eclipse as my platform.
Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|