Java Collection (Medium)

AwedExuberance avatar
AwedExuberance
·
·
Download

Start Quiz

Study Flashcards

30 Questions

Which interface is the root interface for all collection classes?

Iterable

Which interface extends the Collection interface and is used to store an ordered collection of objects?

List

Which class implements the List interface and is a dynamic array that allows duplicate values?

ArrayList

Which class implements the List interface, is a dynamic array, and is synchronized?

Vector

Which class is a subclass of Vector and implements the Last-In-First-Out principle?

Stack

Which class implements the List and Deque interfaces and is a linear data structure that consists of nodes instead of elements?

LinkedList

Which interface is not a true Collection but is fully integrated with Collections?

Map

Which interface extends the Collection interface and implements the First-In-First-Out principle?

Queue

Which data structure can be used both as a queue or a stack and supports common methods like addition and deletion?

Deque

Which data structure is used when we need to process objects based on priority?

PriorityQueue

Which collection does not allow duplicate elements?

Set

Which implementation of Set is ordered and allows iteration through the elements in their order of insertion?

LinkedHashSet

Which implementation of Set provides a total ordering of the elements?

SortedSet

Which data structure stores data as key-value pairs and maps keys to values?

Map

Which of the following is NOT a reason why the Java Collections Framework was introduced?

To introduce new collections in Java

What is the purpose of the Java Collections Framework?

To store and manipulate data of the collections

Which of the following is true about the Java Collections Framework?

It is used for representing, storing, and manipulating data of the collections

What were the standard collections used before the introduction of the Java Collections Framework?

Arrays, Hashtables, and Vectors

What problem did the introduction of the Java Collections Framework solve?

Lack of a common interface for different collections

Which of the following is NOT a class/interface defined in the Java Collections Framework?

LinkedList

What is the hierarchy of the Java Collections Framework?

ArrayList, LinkedList, HashMap, HashSet

Which method is used to add elements to the end of an ArrayList by default?

add()

What is the syntax for creating an ArrayList object?

ArrayList objName = new ArrayList();

Which method is used to access the element at the specified index in an ArrayList?

get(int index)

Which method is used to check whether an ArrayList contains a specified element or not?

contains()

Which method is used to return the size of an ArrayList?

size()

Which method is used to increase the capacity of an ArrayList if necessary?

ensureCapacity(int requiredCapacity)

Which method is used to remove an element from an ArrayList at the specified index?

remove(int index)

Which method is used to update an element in an ArrayList at the specified index?

set(int index, ObjectType element)

Which method is used to sort the elements in an ArrayList in ascending order?

sort()

Study Notes

Java Collections Framework

  • The root interface for all collection classes is Collection.
  • The interface that extends Collection and is used to store an ordered collection of objects is List.
  • ArrayList is a class that implements the List interface and is a dynamic array that allows duplicate values.
  • Vector is a class that implements the List interface, is a dynamic array, and is synchronized.
  • Stack is a class that is a subclass of Vector and implements the Last-In-First-Out principle.
  • LinkedList is a class that implements the List and Deque interfaces and is a linear data structure that consists of nodes instead of elements.
  • Map is an interface that is not a true Collection but is fully integrated with Collections.
  • Queue is an interface that extends the Collection interface and implements the First-In-First-Out principle.
  • Deque is a data structure that can be used both as a queue or a stack and supports common methods like addition and deletion.
  • PriorityQueue is a data structure used when we need to process objects based on priority.
  • Set is a collection that does not allow duplicate elements.
  • LinkedHashSet is an implementation of Set that is ordered and allows iteration through the elements in their order of insertion.
  • TreeSet is an implementation of Set that provides a total ordering of the elements.
  • Map is a data structure that stores data as key-value pairs and maps keys to values.

Purpose and History of Java Collections Framework

  • The Java Collections Framework was introduced to provide a standardized way of working with collections.
  • The purpose of the Java Collections Framework is to provide a set of classes and interfaces that can be used to work with collections of objects.
  • Before the introduction of the Java Collections Framework, standard collections used were Vector, Stack, Dictionary, HashSet, and TreeSet.
  • The introduction of the Java Collections Framework solved the problem of having to implement custom collections for each project.
  • RandomAccess is not a class/interface defined in the Java Collections Framework.

ArrayList

  • The hierarchy of the Java Collections Framework is Collection -> List -> ArrayList.
  • The add() method is used to add elements to the end of an ArrayList by default.
  • The syntax for creating an ArrayList object is ArrayList<> list = new ArrayList<>();.
  • The get() method is used to access the element at the specified index in an ArrayList.
  • The contains() method is used to check whether an ArrayList contains a specified element or not.
  • The size() method is used to return the size of an ArrayList.
  • The ensureCapacity() method is used to increase the capacity of an ArrayList if necessary.
  • The remove() method is used to remove an element from an ArrayList at the specified index.
  • The set() method is used to update an element in an ArrayList at the specified index.
  • The Collections.sort() method is used to sort the elements in an ArrayList in ascending order.

Test your knowledge of Queues and Deques in the Collection framework. Learn about the core principles and implementations of these data structures.

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

Get started for free

More Quizzes Like This

Use Quizgecko on...
Browser
Browser