Arrays, Collections, and Generics
摘要
Data structures are fundamental to programming languages, and fortunately, Java provides a plethora of options to choose for differing situations. In this chapter, we will analyze and exemplify the popular data structures that Java has to offer. We begin the discussion with primitive (and statically-sized) arrays, then move into dynamically-resizable lists, stacks, queues, sets, and maps.We also explain the Java Stream API and its advantages over standard data structure manipulation. We follow the data structure section with type parameterization, or generics, over static methods. While generics are not very powerful when paired only with static methods, we need to understand their role within Java’s Collections framework. The last section is a basic overview of the tree data structure, which will be covered in greater detail in a subsequent computer science text. Java does not provide a tree data structure in the collections framework, so we wrote one for readers to work with.