Question: Using the 3 collections example from the PowerPoint presentation and consolidate them into one program using switch statement. ArrayList The ArrayList class implements the List

Using the 3 collections example from the PowerPoint presentation and consolidate them into one program using switch statement.  Using the 3 collections example from the PowerPoint presentation and consolidate
them into one program using switch statement. ArrayList The ArrayList class implements
the List import java.util."; interface. It uses a dynamic array to store

ArrayList The ArrayList class implements the List import java.util."; interface. It uses a dynamic array to store class TestlavaCollection the duplicate element of different data public static void main(String args[]X types. The ArrayList class maintains the ArrayList list=new ArrayListO://Creating arraylist insertion order and is non-synchronized. list.add("Ravi");//Adding object in arraylist The elements stored in the ArrayList list.add("Vijay"); class can be randomly accessed. list.add("Ravi"); list.add("Ajay"); 1/Traversing list through iterator Iterator itr=list. iterator(); while(itr.hasNextOX Output: System.out.println(ite.next()); } > Vijay Ravi Ravi } Ajay LinkedList LinkedList implements the Collection import java.util. interface. It uses a doubly linked list internally to store the elements. It can store the duplicate public class TestJavaCollection2{ elements. It maintains the insertion order and is public static void main(String args[]){ not synchronized. In LinkedList, the LinkedList al=new LinkedList0; manipulation is fast because no shifting is al.add("Ravi"); required. al.add("Vijay"); al.add("Ravi"); al.add("Ajay"); Iterator itr=al.Iterator(); Output: while(itr.hasNextOX System.out.printin(itr.next()); Ravi > Vijay } } Ravi Ajay Vector Vector uses a dynamic array to store the data elements. It is similar to ArrayList. However, it is synchronized and contains many methods that are not the part of Collection framework. import java.util.*; public class TestJavaCollection3{ public static void main(String args[]X Vector v=new Vector(); v.add("Ayush"); v.add("Amit"); v.add("Ashish"); v.add("Garima"); Iterator itr=v.iterator(); Output: while(itr.hasNext()X System.out.println(itr.next()); > Ayush Amit > Ashish > Garima

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!