我获得了 XML 和架构文件。我的目标是输出 XML 中的所有数据(不重复)并按出生日期对列表进行排序。目前我已经打印了所有数据(有重复项),但我不知道下一步该做什么。我尝试过不同的方法,但没有成功。
最佳答案
HashSet
将取决于Node.equals()
方法来确定相等性,并且您添加不同节点,尽管具有相同的底层文本。来自 the doc :
adds the specified element e to this set if this set contains no element e2 such that (e==null ? e2==null : e.equals(e2))
我将从 String
中提取底层文本 ( Node
) ,以及 HashSet<String>
将正确确定唯一性。
关于java - 从 Java 排序和比较 XML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15407435/