- 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.
- 觸·心:DT時代的大數據精準營銷
- What's New in TensorFlow 2.0
- 區塊鏈架構與實現:Cosmos詳解
- C/C++常用算法手冊(第3版)
- GameMaker Programming By Example
- ADI DSP應用技術集錦
- Nginx實戰:基于Lua語言的配置、開發與架構詳解
- Programming with CodeIgniterMVC
- Natural Language Processing with Python Quick Start Guide
- 人人都能開發RPA機器人:UiPath從入門到實戰
- Flutter之旅
- Python面向對象編程(第4版)
- 用Go語言自制編譯器
- Mastering Data Analysis with R
- AngularJS by Example