Results 1 to 6 of 6
  1. #1
    sanox is offline Member
    Join Date
    Sep 2009
    Posts
    14
    Rep Power
    0

    Default Problem with adding

    Java Code:
    Set<String> set1 = new HashSet();
        Set<String> set2 = new HashSet();
        
        set1.add("red");
        set1.add("yellow");
        set1.add("green");
        set2.add("red");
        set2.add("yellow");
        set2.add("blue");
        
        
        set1.add(set2);
    System.out.print("The value of set1 is " + set1 +" and set2 is " + set2);
    Here is the error
    symbol : method add(java.util.Set<java.lang.String>)
    location: interface java.util.Set<java.lang.String>
    set1.add(set2);
    ^
    Note: C:\Documents and Settings\user\My Documents\JCreator Pro\MyProjects\T.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    1 error

    Process completed.
    Please help. Thanks

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    it is a
    Java Code:
    Set<String>
    not a
    Java Code:
    Set<Set<String>>
    so what makes you think that last one would work?

    You may have wanted to use the addAll method, though.

  3. #3
    sanox is offline Member
    Join Date
    Sep 2009
    Posts
    14
    Rep Power
    0

    Default

    [QUOTE masijade masijade is online now
    Senior Member

    Join Date: Jun 2008
    Posts: 927
    Rep Power: 2
    masijade is on a distinguished road
    Default
    it is a
    Code:

    Set<String>

    not a
    Code:

    Set<Set<String>>

    so what makes you think that last one would work?

    You may have wanted to use the addAll method, though.
    Add to masijade's Reputation][/QUOTE]

    I didnt use as what you said.
    And i cannot use addall method as the question requested to use add() methods. Any ideas?

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    I have no idea what
    Quote Originally Posted by sanox View Post
    I didnt use as what you said.
    is suppossed to mean, but anyway ...

    Then loop through the second Set using The For-Each Loop and the
    Quote Originally Posted by sanox View Post
    add() method
    Although addAll is also an
    Quote Originally Posted by sanox View Post
    add() method
    it is, at least, definately not a delete method.

  5. #5
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    What problem are you trying to solve here?
    It has already been pointed out that you are trying to put a Set inside a Set a Set<String>.
    Set<String> means you can only put Strings in that Set not other Sets.

  6. #6
    sanox is offline Member
    Join Date
    Sep 2009
    Posts
    14
    Rep Power
    0

Similar Threads

  1. Replies: 4
    Last Post: 04-01-2009, 02:03 AM
  2. Problem on adding JButton on JPanel NEED HELP
    By boisk in forum AWT / Swing
    Replies: 15
    Last Post: 03-15-2009, 02:27 PM
  3. Problem Adding Content To JTabbedPane
    By JDCAce in forum AWT / Swing
    Replies: 5
    Last Post: 10-18-2008, 09:45 AM
  4. Replies: 7
    Last Post: 07-09-2008, 12:06 AM
  5. Problem in adding sound.
    By shanky_sanks in forum Java Applets
    Replies: 6
    Last Post: 03-29-2008, 08:37 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
  •