1

I have a public method (called getMusic) in a class called Favorites. getMusic has set. There are 3 sets and in each set has five words, Set getMusic(). In another class called myInterest, there is a treeSet called musicTable. I called getMusic method into myInterest class but I do not know how to iterate over so that the set of words can be added to musicTable TreeSet. I tried to use addAll but it's not working. Where I am going wrong and how do I fix this? .I don't want to use list, I've thought about for loop but not to sure how to use this or literate(). thank you

public class myInterest
{

  private static TreeSet<String> musicTable = new TreeSet<String>();  

  public Test()
   {
     super();
     musicTable = new TreeSet<String>();
   }


  public static void testOut()
  {

    Favorites entrainment = new Favorites(); 

    System.out.println(" " + entrainment.getMusic());

    entrainment.addAll(musicTable); //error msg "cannot find symbol - method addAll(java.util.TreeSet<java.lang.String>)

    musicTable.addAll(entrainment); //also tried this way but error msg "cannot find symbol - method addAll(Favorities) 
  }

}
1
  • 1
    (It's probably not a good idea to set a static field in a constructor.) Commented Jul 14, 2010 at 17:21

1 Answer 1

4

Do you mean:

musicTable.addAll(entrainment.getMusic());

?

Sign up to request clarification or add additional context in comments.

1 Comment

Simon - that's it. Is it possible to explain how I made this mistake?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.