Chapter 10

Set Containers

OBJECTIVES
  • To introduce implementations of Set interface
  • To check whether Sets allow duplicates
  • To introduce the add and remove operations on Sets
  • To introduce the union and difference operations on Sets
  • To develop counting duplicates application
  • To introduce LinkedHashSet’s insertion ordering
  • To introduce TreeSet’s red black tree implementation
10.1 INTRODUCTION

Sets are the third type of Java containers we are going to deal with in this book. Having seen Lists and Map types, we might have observed that lists and maps allow duplicate values. However there are many situations where we need to hold only unique elements. This is where sets score better. In this chapter, the readers will be introduced to Set interface ...

Get JAVA Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.