- The Java Workshop
- David Cuartielles Andreas G?ransson Eric Foster Johnson
- 331字
- 2021-06-11 13:05:25
Summary
This chapter introduced you to the Java collections framework, which is a very powerful tool within the Java language that can be used to store, sort, and filter data. The framework is massive and offers tools in the form of interfaces, classes, and methods, some of which are beyond the scope of this chapter. We have focused on Arrays, Lists, Sets, Maps, and Properties. But there are others, such as queues and dequeues, that are worth exploring on your own.
Sets, like their mathematical equivalents, store unique copies of items. Lists are like arrays that can be extended endlessly and support duplicates. Maps are used when dealing with key-value pairs, something very common in contemporary computing, and do not support the use of two of the same keys. Properties work very much like HashMap (a specific type of Map) but offer some extra features, such as the listing of all their contents to streams, which simplifies the printing out of the contents of a list.
Some of the classes offered in the framework are sorted by design, such as TreeHash and TreeMap, while others are not. Depending on how you want to handle data, you will have to decide which is the best collection.
There are standard techniques for looking through data with iterators. These iterators, upon creation, will point to the first element in a list. Iterators offer some basic methods, such as hasNext() and next(), that state whether there is more data in the list and extract data from the list, respectively. While those two are common to all iterators, there are others, such as listIterator, that are much more powerful and allow, for example, the addition of new elements to a list while browsing through it.
We have looked at a chapter-long example that used many of these techniques, and we have introduced the use of the console to read data through the terminal. In the next chapter, we will cover exceptions and how to handle them.
- Dynamics 365 for Finance and Operations Development Cookbook(Fourth Edition)
- TypeScript Essentials
- C#高級編程(第10版) C# 6 & .NET Core 1.0 (.NET開發經典名著)
- JavaScript 從入門到項目實踐(超值版)
- Mastering matplotlib
- 云計算通俗講義(第3版)
- Python語言實用教程
- Mastering HTML5 Forms
- Java程序設計教程
- Instant Automapper
- Java EE 8 and Angular
- Java Web應用開發
- Swift 2 Blueprints
- Splunk Developer's Guide(Second Edition)
- Serverless從入門到進階:架構、原理與實踐