List list = new LinkedList(); // Doubly-linked list
list = new ArrayList(); // List implemented as growable array
// Append an element to the list
list.add("a");
// Insert an element at the head of the listlist.add(0, "b");
// Get the number of elements in the listint size = list.size(); // 2
// Retrieving the element at the end of the listObject element = list.get(list.size()-1); // a
// Retrieving the element at the head of thelist element = list.get(0); // b
// Remove the first occurrence of an element booleanb = list.remove("b"); // true
b = list.remove("b"); // false // Remove the element at a particular index element = list.remove(0); // a
No comments:
Post a Comment