我刚开始学java。我已经知道 C++ 和 python。 为了学习 Java,我有点用我在 C++ 中所知道的进行类比。 我是 C++ 中 STL 库的狂热用户( vector 、双端队列、堆栈、 HashMap )http://www.sgi.com/tech/stl/stl_introduction.html
同时,python 也有标准的字典、列表等,在他们的文档中很容易理解。
我最近一直在谷歌搜索以找到 Java 中的 STL 等价物,但找不到? 谁能指出我正确的资源?
最佳答案
- std::vector -> j.u.ArrayList
- std::unordered_map -> j.u.HashMap
- std::map -> j.u.TreeMap
- std::set -> j.u.LinkedHashSet
- std::unordered_set -> j.u.HashSet
- std::stack -> j.u.ArrayDeque(不推荐使用 j.u.Stack),
- std::queue -> 使用 j.u.LinkedList(也看看 j.u.ArrayBlockingQueue)。
- std::priority_queue -> j.u.PriorityQueue
- std::span -> 没有明确的类似物
- std::deque -> j.u.ArrayDeque
- std::list -> j.u.LinkedList
- std::forward_list -> 无类似物
重要提示:上述关联具有相似的API,但可能有不同的操作和实现渐近。
注意:j.u
表示java.util
。
关于Java 数据结构/C++ STL 等价物?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9972857/