linked list
package com.company;
import java.util.ArrayList;
import java.util.LinkedList;
public class CWH_92_linkedList {
public static void main(String[] args) {
LinkedList<Integer> l1= new LinkedList<>();
LinkedList<Integer> l2= new LinkedList<>();
l2.add(12);
l2.add(14);
l2.add(16);
l2.add(10);
l2.add(19);
l2.add(34);
//l2.trimToSize();
//l2.add(54);
l1.add(4);
l1.add(1);
l1.add(2);
l1.add(12);
l1.add(9);
l1.add(0,5);
l1.add(0,56);
// l1.addAll(l2);
l1.set(0,45);
// l1.removeRange(1,4);
// l1.remove(6);
// l1.clear(); // clear method
l1.addLast(90);
l1.addFirst(90);
// System.out.println( l1.clone()); //--> clone method
// System.out.println( l1.contains(7)); //--> contains method
// l1.ensureCapacity(500);
// System.out.println( l1.toArray());
// System.out.println( l1.retainAll(l2));
// System.out.println(l1.indexOf(12));
//// System.out.println(l1.lastIndexOf(12));
for(int i =0; i< l1.size();i++){
System.out.print(l1.get(i)+" ");
}
System.out.println(" ");
System.out.println(l1.size());
// for(int e: l1){ ---> second method
// System.out.println(e);
// }
}
}
Comments
Post a Comment