

So it is very helpful when we don’t know capacity of our data structure in advance, we can just declare a List with some initial capacity that automatically increases or decreases its size when elements are added or removed respectively. As List is dynamic in nature, it grows and shrinks according to the requirement.Some of the methods throw ClassCastException if the given object is not compatible with other.Some of the methods throw UnsupportedOperationException if the given collection cannot be modified.If we have more requirement of just retrieving and setting the elements than ArrayList should be preferred, or if we have more requirement of adding and removing the elements (or we can say modification) than LinkedList should be preferred. List has three implementation classes Vector, LinkedList and ArrayList.In Step 3, we have displayed values of these objects.In Step 2, we have used add method to store values in the data structures that we have created in step 1.In Step 1, we have created objects of ArrayList, LinkedList and Vector class, we have defined these objects to store value of String type.In this program objects of all the List implementations (Vector, ArrayList, LinkedList) are created and data of String type is added and then displayed, we have divided this program into 3 Steps that we will discuss one by one. Let us discuss List Interface with the help of program. and it do not implement most of the collection methods. Points that distinguishes vector from arraylist and linkedlist are vectors are Synchronized and also vector is a legacy class that is, it is introduced before JDK 1.2. Vector is also the implementation of List Interface. Operations such as add() and remove() performs better than arrayList whereas operations such as get() and set() performs very poor as compared to arrayList. [b, f, g, a) 4.LinkedList is a class that is also the implementation of List Interface which is implemented using Doubly Linked List, It allows elements to be added dynamically in it, if in case more elements are added than its capacity, linkedlist automatically increases its size.
#Change arraylist notes to notelist code
(a, g, f) 0 N 2 O1 O 3Ĭonsider the following list ArrayList lists = new ArrayList() lists.add('a') lists.add('b') lists.add('f') lists.add('g') what would the list contain after the following code Character c = lists.get(1) lists.remove(1) lists.add(3, 0) 1. What would be the content of the ArrayList list after the given lines of code ArrayList lists = new ArrayList() lists.add('a') lists.add('b') lists.remove(1) lists.add(1)f') lists.add(0, 'g') 1.

public static int compareTo(Object o) O 1 O2 O 3 04 public int compareTo(Object o) 2.public boolean compareTo(String s) 3. The interface comparable has which one of the following methods 1. Transcribed image text: ArrayList list = new ArrayList() list.add("Hello") list.add("book") list.add("Note") list.add("school") which one of the following will change the list to 1.
