Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
ShowAll Questionssorted byDate Posted
Manohar kumar

# compare two Maps

hi... i have seven sets of string and i need to extract values which are same in all seven sets. i tried using for loop but its giving me cpu time limit exceed.Any help would be appreciated.
Thanks

Best Answer chosen by Manohar kumar
Suraj Gharat
Assuming s1, s2, s3....s7 are the seven sets of strings you have, you may try following logic.

```String s2_str=String.join(new List<string>(s2),';');
String s3_str=String.join(new List<string>(s3),';');
String s4_str=String.join(new List<string>(s4),';');
String s5_str=String.join(new List<string>(s5),';');
String s6_str=String.join(new List<string>(s6),';');
String s7_str=String.join(new List<string>(s7),';');

Set<String> commonStrings=new Set<String>();
for(String s:s1){
if(	s2_str.contains(s)	&&
s3_str.contains(s)	&&
s4_str.contains(s)	&&
s5_str.contains(s)	&&
s6_str.contains(s)	&&
s7_str.contains(s)
)
}```

Suraj Gharat
Assuming s1, s2, s3....s7 are the seven sets of strings you have, you may try following logic.

```String s2_str=String.join(new List<string>(s2),';');
String s3_str=String.join(new List<string>(s3),';');
String s4_str=String.join(new List<string>(s4),';');
String s5_str=String.join(new List<string>(s5),';');
String s6_str=String.join(new List<string>(s6),';');
String s7_str=String.join(new List<string>(s7),';');

Set<String> commonStrings=new Set<String>();
for(String s:s1){
if(	s2_str.contains(s)	&&
s3_str.contains(s)	&&
s4_str.contains(s)	&&
s5_str.contains(s)	&&
s6_str.contains(s)	&&
s7_str.contains(s)
)