当前位置: 技术问答>java相关
请指教类集中list系列,map系列和tree系列的异同点,各有什么优势
来源: 互联网 发布时间:2015-08-03
本文导语: 如题,我想做一个个集合,不知道采用什么比较好,请众位指点我一下。 这个帖子我给200分,只要说的清楚明白一定给分,剩下的100分我会另开帖子的。 谢谢! | 仅就sun提供的集中基本数据...
如题,我想做一个个集合,不知道采用什么比较好,请众位指点我一下。
这个帖子我给200分,只要说的清楚明白一定给分,剩下的100分我会另开帖子的。
谢谢!
这个帖子我给200分,只要说的清楚明白一定给分,剩下的100分我会另开帖子的。
谢谢!
|
仅就sun提供的集中基本数据结构说 说:
map是后来提出的
tree好象已经不在提倡使用了
tree能做的,map都能做
如果要兼容以前的程序,用tree
新写程序用map
list没什么体会
map是后来提出的
tree好象已经不在提倡使用了
tree能做的,map都能做
如果要兼容以前的程序,用tree
新写程序用map
list没什么体会
|
list只是存放一种类型的对象,
而map存放一组相关的对象
tree好像和上诉两个不是同一层次的,
think in java这样说:
To review the containers provided in the standard Java library:
An array associates numerical indices 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.
A Collection holds single elements, while a Map holds associated pairs.
Like an array, a List also associates numerical indices to objects—you can think of arrays and Lists as ordered containers. The List automatically resizes itself as you add more elements. But a List can hold only Object references, so it won’t hold primitives and you must always cast the result when you pull an Object reference out of a container.
Use an ArrayList if you’re doing a lot of random accesses, and a LinkedList if you will be doing a lot of insertions and removals in the middle of the list.
The behavior of queues, deques, and stacks is provided via the LinkedList.
A Map is a way to associate not numbers, but objects with other objects. The design of a HashMap is focused on rapid access, while a TreeMap keeps its keys in sorted order, and thus is not as fast as a HashMap.
A Set only accepts one of each type of object. HashSets provide maximally fast lookups, while TreeSets keep the elements in sorted order.
There’s no need to use the legacy classes Vector, Hashtable and Stack in new code.
而map存放一组相关的对象
tree好像和上诉两个不是同一层次的,
think in java这样说:
To review the containers provided in the standard Java library:
An array associates numerical indices 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.
A Collection holds single elements, while a Map holds associated pairs.
Like an array, a List also associates numerical indices to objects—you can think of arrays and Lists as ordered containers. The List automatically resizes itself as you add more elements. But a List can hold only Object references, so it won’t hold primitives and you must always cast the result when you pull an Object reference out of a container.
Use an ArrayList if you’re doing a lot of random accesses, and a LinkedList if you will be doing a lot of insertions and removals in the middle of the list.
The behavior of queues, deques, and stacks is provided via the LinkedList.
A Map is a way to associate not numbers, but objects with other objects. The design of a HashMap is focused on rapid access, while a TreeMap keeps its keys in sorted order, and thus is not as fast as a HashMap.
A Set only accepts one of each type of object. HashSets provide maximally fast lookups, while TreeSets keep the elements in sorted order.
There’s no need to use the legacy classes Vector, Hashtable and Stack in new code.
|
我认为:
list可以做小型数据集操做大型数据较难, 小集合操作方便.
tree可以做为大数据集操作大型数据较容易 .
对于map我很少用, 可以去www.google.com搜索相关的内容.
list可以做小型数据集操做大型数据较难, 小集合操作方便.
tree可以做为大数据集操作大型数据较容易 .
对于map我很少用, 可以去www.google.com搜索相关的内容.
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。