Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

java.util LinkedLists have which of the following properties? (Check all that ap

ID: 3680494 • Letter: J

Question

java.util LinkedLists have which of the following properties? (Check all that apply.) Their add() method requires us to pass a wrapper object, like Float, rather than a primitive, like float to them. They are supplied to us as a generic class, meaning we can declare, in one statement, a LinkedList of user-defined class data just as easily as if we were to define a LinkedList of Float type. They do not require that any ordering relation (like an compareTo()) be defined for the underlying data type. They can be directly declared by passing a primitive data type, like float, to the type parameter, without using a wrapper class, Float. They have an associated generic class ListIterator, which can be used to iterate through LinkedLists.

Explanation / Answer

The java.util LinkedLists class operations perform we can expect for a doubly-linked list. Operations that index into the list will traverse the list from the beginning or the end, whichever is closer to the specified index.

Class declaration:

public class LinkedList<E>

extends AbstractSequentialList<E>

java.util LinkedLists have the following properties:

Parameters

Field

Class constructors

Class methods

Methods inherited

Parameters:

Following is the parameter for java.util LinkedList class:

E -- This is the type of elements held in this collection.

Field:

Fields inherited from class java.util.AbstractList.

Class constructors:

LinkedList()-This constructs constructs an empty list

LinkedList(Collection<? extends E> c)-This constructs a list containing the elements of the specified collection, in the order they are returned by the collection's iterator

Class methods:

boolean add(E e)-

java.util.LinkedList.add(E e)-The java.util.LinkedList.add(E e) method appends the specified element to the end of this list.

  Declaration- public boolean add(E e)

program:

import java.util.*;

public class LinkedListDemo {

public static void main(String[] args) {

// create a LinkedList
LinkedList list = new LinkedList();

// add some elements
list.add("Hello");
list.add(2);
list.add("Chocolate");
list.add("10");

// print the list
System.out.println("LinkedList:" + list);

// add a new element at the end of the list
list.add("Element");

// print the updated list
System.out.println("LinkedList:" + list);
  
}
  
}

output: