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

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.

主站蜘蛛池模板: 乐业县| 诏安县| 桐乡市| 深州市| 宣恩县| 贵州省| 上饶县| 延庆县| 贵定县| 遂平县| 随州市| 古浪县| 新巴尔虎左旗| 磐安县| 鹤山市| 龙州县| 珠海市| 崇仁县| 武宁县| 阿勒泰市| 高清| 田东县| 启东市| 多伦县| 乃东县| 乌苏市| 双流县| 合肥市| 乡宁县| 冀州市| 郁南县| 罗甸县| 闽清县| 泾源县| 郑州市| 周至县| 响水县| 漾濞| 安徽省| 安阳县| 绥芬河市|