Please respond to the following discussion response with a minimum of 200 words and use a reference.
ArrayList:
Characteristics:
The following statement shows how to initialize the ArrayList.
ArrayList list=new ArrayList();
The above list object is used to add different types of components into ArrayList.
ArrayList<String> list=new ArrayList<String>();
The above list object is used to add only the String type component into the ArrayList. If someone tries to add other types of components then it provides a compile-time error.
The following statement shows how to add components into ArrayList.
list.add("Cat");
list.add("Dog");
list.add("Cow");
list.add("Horse");
add() is the method used to add components into the ArrayList. Here the String type is specified so the parameters are enclosed with the double-quotes. Instead of String Integer type is provided then the number is passed as a parameter without double-quotes.
The following statement shows how to update components in ArrayList.
list.set(1,"Goat");
Now the component at index 1 is set as Goat instead of Dog. In the set() method the first parameter specifies the index value and the second parameter specifies the updated component.
The following statements show how to get all the components that were stored in the ArrayList.
for(String str: list)
{
System.out.println(str);
}
From the above statement, the for-each loop is used to iterate the ArrayList to get all the components in the ArrayList.
Iterator it=list.iterator();
while(it.hasNext())
{
System.out.println(it.next());
}
From the above statement, the Iterator interface is used to get the ArrayList components.
The following statement shows how to remove components from the ArrayList.
list.remove(0);
Now the component at index 0 is deleted from the ArrayList.
The following is the java code that implements the ArrayList.
import java.util.*;
public class ArrayListDataStructure
{
public static void main(String[] args)
{
ArrayList<String> list=new ArrayList<String>();
list.add("Cat");
list.add("Parrot");
list.add("Horse");
list.add("Cow");
list.add("Dog");
System.out.println("ArrayList Components");
for(String str:list)
{
System.out.println(str);
}
list.set(2, "Golden Fish");
System.out.println("nArrayList Components after update");
for(String st:list)
{
System.out.println(st);
}
System.out.println("Size of ArrayList:"+list.size());
list.remove(3);
System.out.println("nArrayList Components after Delete");
for(String str:list)
{
System.out.println(str);
}
System.out.println("Size of ArrayList:"+list.size());
list.add("Love Birds");
Collections.sort(list);
System.out.println("nArrayList Components after Sorting");
for(String str:list)
{
System.out.println(str);
}
}
}
LinkedList:
The following statement shows how to initialize the LinkedList.
LinkedList<String> ll=new LinkedList<String>();
The following statement shows how to add components into LinkedList.
ll.add("James");
ll.add("Daniel");
ll.addFirst("Hepson");
ll.addLast("Shibi");
The following statement shows how to update components in LinkedList.
ll.set(2,"Anisha");
The following statements show how to get all the components that were stored in the LinkedList.
for(String st:ll)
{
System.out.println(st);
}
The following statement shows how to remove components from LinkedList.
ll.remove(3);
The following is the java code that implements LinkedList.
import java.util.Collections;
import java.util.LinkedList;
public class LinkedListDataStructure
{
public static void main(String[] args)
{
LinkedList<String> ll=new LinkedList<String>();
ll.add("Dhanya");
ll.add("Daniel");
ll.add("Xavier");
ll.addFirst("Hepson");
ll.addLast("Shibi");
System.out.println("LinkedList Components");
for(String st:ll)
{
System.out.println(st);
}
ll.set(2,"Anisha");
System.out.println("nLinkedList Components after update");
for(String st:ll)
{
System.out.println(st);
}
System.out.println("Size of LinkedList:"+ll.size());
ll.remove(3);
System.out.println("nLinkedList Components after Delete");
for(String st:ll)
{
System.out.println(st);
}
System.out.println("Size of LinkedList:"+ll.size());
Collections.sort(ll);
System.out.println("nLinkedList Components after Sorting");
for(String st:ll)
{
System.out.println(st);
}
}
}
Vector:
The following statement shows how to initialize a Vector class.
Vector<String> vec=new Vector<String>();
The following statement shows how to add components to a Vector.
v.addElement("Cake");
v.addElement("Biscuit");
v.addElement("IceCream");
v.addElement("Chocolate");
The following statement shows how to update components in Vector.
v.set(1,"Drinks");
The following statement shows how to remove components from the Vector.
v.remove(3);
The following is the java code that implements Vector.
import java.util.Collections;
import java.util.Vector;
public class VectorDataStructure
{
public static void main(String[] args)
{
Vector<String> v =new Vector<String>();
v.addElement("Cake");
v.addElement("Biscuit");
v.addElement("IceCream");
v.addElement("Chocolate");
System.out.println("Vector Components");
for(String st:v)
{
System.out.println(st);
}
v.set(1,"Drinks");
System.out.println("nVector Components after update");
for(String st:v)
{
System.out.println(st);
}
System.out.println("Size of Vector:"+v.size());
v.remove(3);
System.out.println("nVector Components after Delete");
for(String st:v)
{
System.out.println(st);
}
System.out.println("Size of Vector:"+v.size());
v.add("Biscuit");
Collections.sort(v);
System.out.println("nVector Components after Sorting");
for(String st:v)
{
System.out.println(st);
}
}
}
ArrayList:
The ArrayList is a resizable array that can be used to store different types of components at any time. In ArrayList components can be added anywhere by specifying the index.
The following is the description of the code
LinkedList:
LinkedList class is used to implement the Linked List linear data structure. The components are not stored in the neighboring address and it is stored as containers.
The following is the description of the code.
Snip of the Output:
Vector:
Vector is the growable array. Vector is synchronized so it has legacy methods. Iterators can not be returned by the vector class because if any concurrent changes occur then it throws the ConcurrentModificationException.
The following is the description of the code
Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.
You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.
Read moreEach paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.
Read moreThanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.
Read moreYour email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.
Read moreBy sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.
Read more