Results 1 to 4 of 4
  1. #1
    pooja123 is offline Member
    Join Date
    Mar 2011
    Posts
    5
    Rep Power
    0

    Default error in HashSet

    Hi,

    I have a small program here where in im learning to use HashMap.

    import java.util.HashSet;
    import java.util.Set;

    public class test {

    public static void main(String[] args) {
    Set set = new HashSet();
    set.add("pooja");
    if(set.contains("pooja")) {
    System.out.println("contains"); }
    else {
    System.out.println("does not contain"); }
    }
    }

    But when i try to run this, it gives me an error saying
    "Note: test.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details."

    Can anyone tell me what does this error mean ? and what do i do to make this program run ??

    Thank you in advance ..

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default

    Cross posted error in HashSet

  3. #3
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    283
    Rep Power
    7

    Default

    @pooja123

    You must have seen the reply in the cross post. It says The collection you are using is not specified to hold any particular class. So considering your example, the collection is storing a String. That means your declaration should go like this

    Java Code:
    Set<String> set = new HashSet<String>();
    Swastik

  4. #4
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    Quote Originally Posted by pooja123 View Post
    Can anyone tell me what does this error mean ? and what do i do to make this program run ??

    it not an error, its a warning

    test.java:10: warning: [unchecked] unchecked call to add(E) as a member of the raw type java.util.Set
    set.add("pooja");
    ^
    1 warning

    try with Set<String> set = new HashSet<String>(); and the warning will disappear.

Similar Threads

  1. HashSet
    By Dayanand in forum New To Java
    Replies: 7
    Last Post: 03-12-2011, 10:37 AM
  2. Getting value for key in HashSet
    By Venny in forum New To Java
    Replies: 12
    Last Post: 02-02-2011, 09:42 AM
  3. Adding to a HashSet
    By Neivaed in forum New To Java
    Replies: 6
    Last Post: 12-05-2010, 07:16 PM
  4. :( anyone here plz help on HashSet
    By waklo99 in forum New To Java
    Replies: 8
    Last Post: 09-20-2010, 04:02 AM
  5. HashSet Contains problem
    By guywalder in forum Advanced Java
    Replies: 11
    Last Post: 09-01-2009, 03:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •