Assuming by "list" you mean java.util.List:
java.util.List.remove(int index);
In the event you are referring to javax.swing.JList:
simply manipulate your Object[] or whatever data you are using for your ListData and reassign your List to contain said listData:
javax.swing.JList.setListData(Object[] listData);
(And I am assuming that you're using an Object[] instead of a Vector, which is also usable in said circumstance)
And, finally, if you are using the java.awt.List:
java.awt.List.remove(int position);
java.awt.List.remove(String item);
import java.util.Iterator;
import java.util.HashSet;
import java.util.Set;
/**
* A doubly linked list as introduced in lecture 6 in IN2002. Template for
* coursework 2a in 2006.
*/
public class DLList implements Iterable {
/**
* Inner class for doubly linked list nodes.
*/
class DLNode {
Object info; // the data element
DLNode next; // the next node
DLNode prev; // the previous node
DLNode(Object argInfo) {
info = argInfo;
}
}
private DLNode head, tail;
private int count;
/**
* Appends an object at the tail of this list.
* @param argOb The object to append.
*/
public void appendAtTail(Object argOb) {
DLNode node = new DLNode(argOb); // new node
if (tail == null) { // empty list
tail = node;// set the tail
head = tail;// and head
} else {// non-empty list
tail.next = node; // connect the
node.prev = tail;// new node
tail = node;// set the tail
}
count++;// udpate count
}
/**
* Deletes the given node maintaining the list structure.
* @param node The node to delete, must be in the list.
*/
private void delete(DLNode node) {
..............................?
..............................?
take the head value of the node you want to delete and set it equal to the head node's tail.
take the tail value of the node you want to delete and set it equal to the tail node's head.
So that this:
H<>D<->T
Becomes this:
H<>T
Nothing refers to the D node, so it's eligible for GC.
%