我应该使用什么Java集合? [英] What Java Collection should I use?

查看:127
本文介绍了我应该使用什么Java集合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此问题中获得许可。最简单的归因是




$ b

其他资源

主要的其他有用的参考可能是从oracle文档的以下页面,其中描述每个 Collection



HashSet与TreeSet



有关何时使用 HashSet TreeSet 的详细讨论:
Hashset vs Treeset



ArrayList与LinkedList



详细讨论:何时在ArrayList上使用LinkedList?


In this question How can I efficiently select a Standard Library container in C++11? is a handy flow chart to use when choosing C++ collections.

I thought that this was a useful resource for people who are not sure which collection they should be using so I tried to find a similar flow chart for Java and was not able to do so.

What resources and "cheat sheets" are available to help people choose the right Collection to use when programming in Java? How do people know what List, Set and Map implementations they should use?

解决方案

Since I couldn't find a similar flowchart I decided to make one myself.

This flow chart does not try and cover things like synchronized access, thread safety etc or the legacy collections, but it does cover the 3 standard Sets, 3 standard Maps and 2 standard Lists.

This image was created for this answer and is licensed under a Creative Commons Attribution 4.0 International License. The simplest attribution is by linking to either this question or this answer.

Other resources

The main other useful reference to people is probably the following page from the oracle documentation which describes each Collection.

HashSet vs TreeSet

There is a detailed discussion of when to use HashSet or TreeSet here: Hashset vs Treeset

ArrayList vs LinkedList

Detailed discussion: When to use LinkedList over ArrayList?

这篇关于我应该使用什么Java集合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆