-3

In my application i should get the data from java.awt.List, and delete the particular value form the list.How can I do it? Please give me the suggestions.

My code

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);
}   
Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
kanna
  • 469
  • 2
  • 6
  • 10
  • 4
    *"Plz give me the suggestions."* 1) For better help sooner, post an [SSCCE](http://sscce.org/). 2) Please use the correct spelling for words like 'you', 'your' & 'please'. This makes it easier for people to understand and help. 3) Why AWT rather than Swing? See this answer on [Swing extras over AWT](http://stackoverflow.com/a/6255978/418556) for many good reasons to abandon using AWT components. If you need to support older AWT based APIs, see [Mixing Heavyweight and Lightweight Components](http://www.oracle.com/technetwork/articles/java/mixing-components-433992.html). – Andrew Thompson May 09 '13 at 10:13
  • 3
    3) Are you sure did you really search before asking ? – Alexis C. May 09 '13 at 10:13
  • yes.Really i searched a lot.i couldn't get inside the function. – kanna May 09 '13 at 10:15
  • 1
    Where is `list` defined? Is that just a typo for `lst`? – Duncan Jones May 09 '13 at 10:16
  • 1
    You really want to post something that people could copy, paste and run (or that you think *should* run, but doesn't). – Richard Tingle May 09 '13 at 10:16
  • Do you know the usage of entrySet()? – Shreyos Adikari May 09 '13 at 10:17
  • i know..i get the data from map and stored into java.awt.List.From that i cant get the data. – kanna May 09 '13 at 10:20
  • Can I double check you are really writing an AWT graphical application? Otherwise, you probably want to use `java.util.List`. – Duncan Jones May 09 '13 at 10:21
  • 1
    Have look this Link http://samplecodez.com/java/list.php Hope it's help you... – Janny May 09 '13 at 10:23

1 Answers1

3

You can use getItemsCount() and then use for(int i = 0; i < n; i++) to iterate over the items and remove item using remove(i).

AlexR
  • 114,158
  • 16
  • 130
  • 208
  • +1 but notice, I'd suggest to for (int i = model.getRowCount() - 1; i > -1; i--) { instead, because DefaultListModel descreasing no. Items internally, just to avoiding index(or whatever) arrays exception – mKorbel May 09 '13 at 10:23