Tutorials Point


  Java Basics Examples
  Java Tutorial
  Java Useful Resources
  Selected Reading

© 2011 TutorialsPoint.COM


  Home     References     Discussion Forums     About TP  

Java Examples - Clear elements of LinkedList


previous next AddThis Social Bookmark Button


Problem Description:

How to delete many elements from a linkedList?

Solution:

Following example demonstrates how to delete many elements of linkedList using Clear() method.

import java.util.*;

public class Main {
   public static void main(String[] args) {
      LinkedList lList = new LinkedList();
      lList.add("1");
      lList.add("8");
      lList.add("6");
      lList.add("4");
      lList.add("5");
      System.out.println(lList);
      lList.subList(2, 4).clear();
      System.out.println(lList);
   }
}

Result:

The above code sample will produce the following result.

[one, two, three, four, five]
[one, two, three, Replaced, five]


previous next Printer Friendly



  

Advertisement

Online Image Processing

Indian Baby Names