gpt4 book ai didi

java - 在java中搜索重复的组合键

转载 作者:行者123 更新时间:2023-12-02 11:11:29 24 4
gpt4 key购买 nike

我想消除存储在列表列表中的重复按键组合,并希望获得有关删除或标记重复项的有效方法的建议。让我用一个简单的例子来解释这个问题。我有一个列表,其中包含部分名称作为列表中的单独元素。一个人的名字可以有 2 - n 个部分。

基本列表中的元素包含人名的各个部分,并且可以以任何顺序出现,在本例中,它具有三个部分 {“Rajesh”、“Kumar”、“Singh”}。同样,可以有一个人名列表,其姓名按任意顺序出现,如下所示

0 = { "Rajesh", "Kumar", "Singh" }
1 = { "William", "Robert" }
2 = { "John", "Anderson", "Jr" }
3 = { "Kumar", "Rajesh", "Singh" }

上面列表中的项目编号 3 需要被删除,因为它正好有 3 个项目,并且这些部件与项目 0 匹配,尽管它们的出现顺序不同。

谢谢

最佳答案

将元素存储在 Set<Set<String>> 中。集合是无序的,因此查找不关心组内的原始顺序。 Set.equals :

Compares the specified object with this set for equality. Returns true if the specified object is also a set, the two sets have the same size, and every member of the specified set is contained in this set (or equivalently, every member of this set is contained in the specified set). This definition ensures that the equals method works properly across different implementations of the set interface.

关于java - 在java中搜索重复的组合键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50591657/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com