Thursday, 15 October 2015

LinkedList example in java

import java.util.*;


public class First {

public static void main(String[] args) {
// TODO Auto-generated method stub
LinkedList<Integer> obj = new LinkedList<Integer>();
obj.add(10);
obj.add(12);
obj.add(13);
obj.add(23);
obj.add(13);
Iterator it = obj.iterator();
while(it.hasNext()){
System.out.println("The value is  " +it.next());
}
obj.remove(2);
System.out.println("The value is  " +obj);
int l = obj.size();
System.out.println("the value of l is " +l);
}
}


output:-
The value is  10
The value is  12
The value is  13
The value is  23
The value is  13
The value is  [10, 12, 23, 13]
the value of l is 4

No comments:

Post a Comment