Saturday 25 October 2014

Java : Collection Framework : LinkedList (Remove Object)


Click here to watch in Youtube : https://www.youtube.com/watch?v=EUWRFwawwTs

LinkedListRemoveExample.java
import java.util.LinkedList;

/*
 * Example of remove(int index) and remove(Object o) methods
 */
public class LinkedListRemoveExample
{

    public static void main(String[] args)
    {
        LinkedList<String> linkedList = new LinkedList<String>();
        linkedList.add("Ram");
        linkedList.add("Dave");
        linkedList.add("Peter");
        linkedList.add("Julia");
        linkedList.add("Akram");

        System.out.println("linkedList : " + linkedList + "\n");

        /*
         * Remove element from the index position 1.
         */

        linkedList.remove(1);

        System.out
                .println("linkedList After removing element from the index 1 : "
                        + linkedList + "\n");

        /*
         * Remove the String object Julia.
         */

        linkedList.remove("Julia");

        System.out
                .println("linkedList After removing String object \"Julia\" : "
                        + linkedList);
    }

}

Output
linkedList : [Ram, Dave, Peter, Julia, Akram]

linkedList After removing element from the index 1 : [Ram, Peter, Julia, Akram]

linkedList After removing String object "Julia" : [Ram, Peter, Akram]

To Download LinkedListDemoRemove Project Click the below link

https://sites.google.com/site/javaee4321/java-collections/LinkedListDemoRemove.zip?attredirects=0&d=1

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • No comments:

    Post a Comment