官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 汽车| 花莲市| 红安县| 建昌县| 秦皇岛市| 博湖县| 寿光市| 和林格尔县| 历史| 吉安市| 元江| 洞口县| 博客| 九江市| 德庆县| 都兰县| 定南县| 青龙| 永济市| 抚州市| 乐至县| 连云港市| 昂仁县| 读书| 福建省| 紫金县| 宝兴县| 三台县| 横山县| 淮南市| 璧山县| 兴山县| 龙南县| 榆树市| 弥渡县| 崇信县| 德保县| 海南省| 寿光市| 吴桥县| 贵州省|