2010-07-14 86 views
1

我有一個名爲Favorites的類中的公共方法(稱爲getMusic)。 getMusic已設置。有三組,每組有五個單詞Set getMusic()。在另一個名爲myInterest的類中,有一個名爲musicTable的treeSet。我將getMusic方法調用到myInterest類中,但我不知道如何迭代以便可以將這組單詞添加到musicTable TreeSet中。我試圖使用addAll,但它不工作。我哪裏出錯了,我該如何解決這個問題? 。我不想使用列表,我想過循環,但不知道如何使用這個或literate()。謝謝添加另一組字符串樹 - java

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

(在構造函數中設置靜態字段可能不是一個好主意。) – 2010-07-14 17:21:07

回答

4

你的意思是:

musicTable.addAll(entrainment.getMusic()); 

+0

+1:這也是我的第一個想法。 – Powerlord 2010-07-14 17:11:43

+0

西蒙 - 就是這樣。有沒有可能解釋我是如何犯這個錯誤的? – DiscoDude 2010-07-14 17:13:02

相關問題