这个问题是在我接受 Adobe 采访时向我提出的。我回答可以用hashmap,但是他不满意。
文件1
< tag1 >
< subtag1 >
< subsubtag1 >
</subsubtag1 >
< /subtag1 >
< /tag1 >
< tag2 >
< /tag2 >
n 数量的此类文件(即 XML 文件)需要存储在内存中。编写一个 java 数据结构的实现,用于将这些文件存储在内存中,以有效地执行以下操作:
- 访问特定文件中的特定标签。
- 访问所有包含该标签的文件中的特定标签。
注意:
- 有数百万个文件要存储
- 每个文件包含数百万个标签,每个标签可能包含数百万个子标签
最佳答案
我想到了 TreeSet
。
Access and retrieval times are quite fast, which makes TreeSet an excellent choice when storing large amounts of sorted information that must be found quickly.
类似的东西:
public class Storage{
private String mTagName;
private String mAttribute;
private TreeSet<Storage> mTree;
}
包含自身 TreeSet
的类。适合递归。
关于java - 应该使用哪个集合来存储内存中的xml文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18936899/