Which collection type does NOT allow duplicate elements?
Java Collection Framework
The Collections Framework (interfaces, implementations, algorithms), Collection vs. Map, Set vs. List, ArrayList and its methods, iterators, the diamond <>, Collections.sort and Collections.binarySearch.
How to read this page
Every original slide is shown unchanged. Yellow marks on a slide point to a numbered note: hover or tap a mark to jump to its note, and hover a note to see its marks. Questions tagged Past exam appeared on a real paper; Prediction questions are likely angles, not confirmed. Pick an answer to each question: a wrong pick tells you why it is wrong, so you can try again.
All 33 slides
- 1 Slide 1
- 2 Objective
- 3 Java Collections Framework
- 4 Collections Framework is a unified architecture for managing collections
- 5 Interfaces
- 6 Collections Framework Implementations
- 7 Collection
- 8 Map
- 9 Operations
- 10 Collections Methods
- 11 Slide 11
- 12 Slide 12
- 13 A List (sometimes called a sequence ) is an
- 14 Array List
- 15 Array List
- 16 Introduction to Collections and Class ArrayList
- 17 Introduction to Collections and Class ArrayList (Cont.)
- 18 Slide 18
- 19 Introduction to Collections and Class ArrayList (Cont.)
- 20 Slide 20
- 21 Slide 21
- 22 Slide 22
- 23 Code Example: ArrayListCollection
- 24 and ArrayList Iterator
- 25 Collection Interface
- 26 Slide 26
- 27 and ArrayList Iterator
- 28 Method sort
- 29 Arrays static asList
- 30 Collection Method Sort
- 31 Slide 31
- 32 Binary Search
- 33 public class GFG { public static void main(String[] args) {
Collections Framework is a unified architecture for managing collections
Notes
Three parts: interfaces, implementations (classes), algorithms (static methods in Collections).
Interfaces
Notes
Core interfaces: Collection, Set (no duplicates), List (ordered, duplicates allowed), Queue, Map (key → value).
Exam angle
Map
Notes
Map is NOT a Collection: it stores key–value pairs.
Exam angle
Map extends the Collection interface.
Array List
Notes
ArrayList: like an array but resizes automatically; holds objects only (Integer, not int).
Exam angle
An ArrayList<int> declaration:
Introduction to Collections and Class ArrayList (Cont.)
Notes
Methods: add, add(index, e), get, set, remove, size, contains, indexOf, clear, isEmpty.
Exam angle
Which returns the number of elements in an ArrayList list?
and ArrayList Iterator
Notes
Iterator: hasNext(), next(), remove(): the safe way to remove while iterating.
Exam angle
Removing elements from a list inside a for-each loop is safe.
- Use an Iterator’s remove() (else ConcurrentModificationException).
Binary Search
Exam angle
Collections.binarySearch requires the list to be: