2013-05-09 31 views
-3

在我的應用程序中,我應該從java.awt.List中獲取數據,並刪除列表中的特定值。如何才能做到這一點?請給我一些建議。從java.awt.List中獲取數據

我的代碼

import java.awt.List; 

List lst=new List(15,false); 
for (Entry<String, String> entry : list.entrySet()) { 
    String client_Name=entry.getKey(); 
    lst.add(client_Name + "\n");//here i should get the data and delete particular data 
    String listName=lst.getName(); 
    System.out.println(listName); 
} 
+4

*「Plz給我建議。」* 1)爲了更快地獲得更好的幫助,請發佈[SSCCE](http://sscce.org/)。 2)請爲'you','your'和'please'等單詞使用正確的拼寫。這使人們更容易理解和幫助。 3)爲什麼是AWT而不是Swing?在[Swing extras over AWT]上看到這個答案(http://stackoverflow.com/a/6255978/418556)有很多很好的理由放棄使用AWT組件。如果您需要支持較老的基於AWT的API,請參閱[混合重量級和輕量級組件](http://www.oracle.com/technetwork/articles/java/mixing-components-433992.html)。 – 2013-05-09 10:13:25

+3

3)你確定在詢問之前是否確實搜索過? – 2013-05-09 10:13:47

+0

是的。真的我搜索了很多,我無法進入功能。 – kanna 2013-05-09 10:15:34

回答

3

您可以使用getItemsCount(),然後使用for(int i = 0; i < n; i++)遍歷項目,並使用remove(i)刪除項目。

+0

+1,但通知,我建議爲(INT I = model.getRowCount() - 1;我> -1;我 - ){相反,因爲DefaultListModel descreasing沒有。內部項目,只是爲了避免索引(或其他)數組異常 – mKorbel 2013-05-09 10:23:17