Summary of "Holding Your Objects"
来源:互联网 发布:自制数据库 编辑:程序博客网 时间:2024/06/13 03:49
Summary
Java provides a number of ways to hold objects:
1.
An array associates numerical indexes to objects. It holds objects of a known type so that you don’t have to cast the result when you’re looking up an object. It can be multidimensional, and it can hold primitives. However, its size cannot be changed once you create it.
2.
A Collection holds single elements, and a Map holds associated pairs. With Java generics, you specify the type of object to be held in the containers, so you can’t put the wrong type into a container and you don’t have to cast elements when you fetch them out of a container. Both Collections and Maps automatically resize themselves as you add more elements. A container won’t hold primitives, but autoboxing takes care of translating primitives back and forth to the wrapper types held in the container.
3.
Like an array, a List also associates numerical indexes to objects— thus, arrays and Lists are ordered containers.
1.
An array associates numerical indexes to objects. It holds objects of a known type so that you don’t have to cast the result when you’re looking up an object. It can be multidimensional, and it can hold primitives. However, its size cannot be changed once you create it.
2.
A Collection holds single elements, and a Map holds associated pairs. With Java generics, you specify the type of object to be held in the containers, so you can’t put the wrong type into a container and you don’t have to cast elements when you fetch them out of a container. Both Collections and Maps automatically resize themselves as you add more elements. A container won’t hold primitives, but autoboxing takes care of translating primitives back and forth to the wrapper types held in the container.
3.
Like an array, a List also associates numerical indexes to objects— thus, arrays and Lists are ordered containers.
4.
Use an ArrayList if you’re doing a lot of random accesses, but a LinkedList if you will be doing a lot of insertions and removals in the middle of the list.
5.
The behavior of Queues and stacks is provided via the LinkedList.
6.
A Map is a way to associate not integral values, but objects with other objects. HashMaps are designed for rapid access, whereas a TreeMap keeps its keys in sorted order, and thus is not as fast as a HashMap. A LinkedHashMap keeps its elements in insertion order, but provides rapid access with hashing.
7.
A Set only accepts one of each type of object. HashSets provide maximally fast lookups, whereas TreeSets keep the elements in sorted order. LinkedHashSets keep elements in insertion order.
8.
There’s no need to use the legacy classes Vector, Hashtable, and Stack in new code.
It’s helpful to look at a simplified diagram of the Java containers (without the abstract classes or legacy components). This only includes the interfaces and classes that you will encounter on a regular basis.
Use an ArrayList if you’re doing a lot of random accesses, but a LinkedList if you will be doing a lot of insertions and removals in the middle of the list.
5.
The behavior of Queues and stacks is provided via the LinkedList.
6.
A Map is a way to associate not integral values, but objects with other objects. HashMaps are designed for rapid access, whereas a TreeMap keeps its keys in sorted order, and thus is not as fast as a HashMap. A LinkedHashMap keeps its elements in insertion order, but provides rapid access with hashing.
7.
A Set only accepts one of each type of object. HashSets provide maximally fast lookups, whereas TreeSets keep the elements in sorted order. LinkedHashSets keep elements in insertion order.
8.
There’s no need to use the legacy classes Vector, Hashtable, and Stack in new code.
It’s helpful to look at a simplified diagram of the Java containers (without the abstract classes or legacy components). This only includes the interfaces and classes that you will encounter on a regular basis.
Simple Container Taxonomy
You’ll see that there are really only four basic container components—Map, List, Set, and Queue—and only two or three implementations of each one (the java.util.concurrent implementations of Queue are not included in this diagram). The containers that you will use most often have heavy black lines around them.
The dotted boxes represent interfaces, and the solid boxes are regular (concrete) classes. The dotted lines with hollow arrows indicate that a particular class is implementing an interface. The solid arrows show that a class can produce objects of the class the arrow is pointing to. For example, any Collection can produce an Iterator, and a List can produce a ListIterator (as well as an ordinary Iterator, since List is inherited from Collection).
The dotted boxes represent interfaces, and the solid boxes are regular (concrete) classes. The dotted lines with hollow arrows indicate that a particular class is implementing an interface. The solid arrows show that a class can produce objects of the class the arrow is pointing to. For example, any Collection can produce an Iterator, and a List can produce a ListIterator (as well as an ordinary Iterator, since List is inherited from Collection).
1 0
- Summary of "Holding Your Objects"
- container Holding Your Objects
- Chapter 8:Holding your objects
- Holding Your Objects 1-4
- 13 Holding Your Objects课后练习
- 《JAVA编程思想》学习备忘:Holding Your Objects-1
- Think In Java 笔记7 Holding Your Objects
- 去掉 评论中的Summary of Your Review
- The Core Objects of Your App
- Know the Core Objects of Your App
- Holding you objects
- Holding Your Object 5-14
- Holding Your Object(Part C Map)
- Summary of this part
- Summary of keyword synchronized
- SUMMARY OF JANE EYRE
- SUMMARY OF CREATIONAL PATTERNS
- SUMMARY OF STRUCTURAL PATTERNS
- ArcGIS API for JavaScript 地图加载空白现象-ArcGIS Web 开发学习(三)
- My97DatePicker日期范围限制
- hadoop 操作(二)
- 使用JDK中JAXBContext对JavaBean和xml相互转换
- 格子中输出(改进版,可改变输出行数,列数)
- Summary of "Holding Your Objects"
- css-before 和 after的妙用
- IE11的离线安装
- 实战 SQL Server 2008 数据库误删除数据的恢复
- zookeeper 集群安装(单点与分布式成功安装)摘录
- 总结之前遇到的并解决了的问题(二)
- 自定义控件——初识自定义控件
- django mongoengine 判断mongoengine定义的字段类型
- 表格中显示数据