Java 在HashSet中搜索
我有两个哈希集Java 在HashSet中搜索,java,search,generics,collections,Java,Search,Generics,Collections,我有两个哈希集 Set<String> firstSet = new HashSet<String>(); Set<String> secondSet= new HashSet<String>(); 或者他们有什么合适的方法来实现这一点吗?将firstSet改为地图 final Map map<String, String> = new HashMap<String, String(); map.put("A", "ABC");
Set<String> firstSet = new HashSet<String>();
Set<String> secondSet= new HashSet<String>();
或者他们有什么合适的方法来实现这一点吗?将firstSet改为地图
final Map map<String, String> = new HashMap<String, String();
map.put("A", "ABC");
map.put("B", "BCD");
...
map.keySet().containsAll(secondSet);
final Map Map=new hashmap是否要获取firstSet中包含secondSet子集的所有元素?您想要的输出是什么?@Rohit输出是从第一个集合中获取第二个集合中的所有元素[A,B,C,D,L]。希望是清楚的。嗨,Rohit…是的,实际上我想得到firstSet的所有元素,它们包含secondSet中的子集。他们是否可以使用集合来实现此目的。输出是从第一个集合中获取第二个集合中的所有元素,例如[A、B、C、D、L]。我们是否仍然可以使用哈希集合而不使用哈希映射?是否可能?第二个集合中的元素都不存在于第一个集合中。如果您想解析第一个集合的内容以查看元素是否以第二个集合中的元素开始,那么您必须自己查看每个条目。
final Map map<String, String> = new HashMap<String, String();
map.put("A", "ABC");
map.put("B", "BCD");
...
map.keySet().containsAll(secondSet);