Java LinkedList remove Example
LinkedList class remove method example. This example shows you how to use remove method.
LinkedList class remove method example.public LinkedList remove(int index) Removes the element at the specified position in this list. Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the list.
Here is the code
/**
* @ # Remove1.java
* A class repersenting use to Remove1 method of LinkedList class in java.util package
* version 15 May 2008
* author Rose India
*/
import java.util.*;
public class Remove1 {
public static void main(String args[]) {
LinkedList list = new LinkedList();
int i = 11;
String str = "Rose";
//Add the specified element to the end of this list.
list.add(i);
list.add(str);
list.add("India");
//Remove element
System.out.println("Removed lement " + list.remove(1));
System.out.println("list = " + list);
}
} |
Output
Removed lement Rose
list = [11, India] |
|