Large arrays make runtime very slow So I have the following code that takes the input of two arrays, and apply some queries to match elements from DBpediaClassesArray with elements from YagoClassesArray, then it returns the number of elements that are similar in the two ArrayLists.
    public static void get_ND_Matches() throws IOException{
    @SuppressWarnings(&quot;rawtypes&quot;)
    List&lt;String&gt; DBpediaClassesArray = new ArrayList&lt;String&gt;();
    List&lt;String&gt; YagoClassesArray = new ArrayList&lt;String&gt;();
    DBpediaClassesArray = new ArrayList&lt;String&gt;( ClassesRetrieval.getDBpediaClasses());
    YagoClassesArray = new ArrayList&lt;String&gt;( ClassesRetrieval.fileToArrayListYago());
    String YagoClassWithMaxMatches=&quot;&quot;;
    HashMap&lt;String,Integer&gt; mappingYagoLabelMaxValue = new HashMap&lt;String,Integer&gt;();
    int NumberOfCommonInstances;        
    HashMap&lt;String,ArrayList&lt;String&gt;&gt; MappingYagoClassWithInstances = new HashMap&lt;&gt;();
    
    for(String yagoClass:YagoClassesArray){
        MappingYagoClassWithInstances.put(yagoClass, GetYagooClassInstances(yagoClass));
        System.out.println(&quot;Done for : &quot;+yagoClass );
    }        
    for(String dbClass:DBpediaClassesArray){
        ArrayList&lt;String&gt; DBpediaInstancesArray = GetDBpediaClassInstances(dbClass);
        for(Map.Entry&lt;String, ArrayList&lt;String&gt;&gt; YagoMapEntry : MappingYagoClassWithInstances.entrySet()){
            String yagoClass=YagoMapEntry.getKey();
            Set&lt;String&gt; IntersectionSet =Sets.intersection(Sets.newHashSet(DBpediaInstancesArray), Sets.newHashSet(YagoMapEntry.getValue()));
            //System.out.println(dbClass + &quot; and &quot;+ yagoClass+ &quot; = &quot;+ IntersectionSet.size());
            NumberOfCommonInstances = IntersectionSet.size();
            mappingYagoLabelMaxValue.put(yagoClass, NumberOfCommonInstances);
        }    
        int MaximumValueOfIntersection=(Collections.max(mappingYagoLabelMaxValue.values()));
        for(Entry&lt;String, Integer&gt; YagoLabelToValueEntry:mappingYagoLabelMaxValue.entrySet()){
            if(YagoLabelToValueEntry.getValue()==MaximumValueOfIntersection &amp;&amp; MaximumValueOfIntersection != 0){
                 YagoClassWithMaxMatches = YagoLabelToValueEntry.getKey();
            }
            if(MaximumValueOfIntersection==0){
                YagoClassWithMaxMatches = &quot;Nothing in yago&quot;;
            }
        }
        System.out.println(&quot;-------------------------------&quot;);
        System.out.println(dbClass+&quot; Corresponds to &quot;+ YagoClassWithMaxMatches+&quot; with : &quot;+MaximumValueOfIntersection);
        System.out.println(&quot;-------------------------------&quot;);
        
    }
}

This code returns for example:

Actor from DBPEDIA Corresponds to Yago_Actor
Album from DBPEDIA Corresponds to Yago_Album
SomeClass from DBPEDIA Corresponds to nothing in Yago

Etc..
Behind the scenes, this code uses getDBpediaClasses and then applies GetDBpediaClassInstances method to get an ArrayList of results for each class. Each ArrayList resulted is then compared to another ArrayList generated by GetYagooClassInstances for each class of fileToArrayListYago().
Now, because of all the calculations made in the background (there are millions of elements in each array), this process takes hours to execute, because it runs each comparison after another, while it would be better to get them all done at once and then just get the YagoClassWithMaxMatches after all of them have been computed.
I was thinking of concurrency, but I first wanted to see if there is an easier way.
Are there any suggestions to make the code run faster?
First I must encourage you to follow java conventions. Local variables and methods should be typed in lowerCamelCase. You shouldn't also assign a variable twice if you can avoid it for example you shouldn't do this 


List&lt;String&gt; DBpediaClassesArray = new ArrayList&lt;String&gt;();
DBpediaClassesArray = new ArrayList&lt;String&gt;( ClassesRetrieval.getDBpediaClasses());



You could also guive a better name to this variable, the array sufix isn't doing much there, I would prefer dbpediaClasses.
You should do this instead:

List&lt;String&gt; dbpediaClasses= new ArrayList&lt;String&gt;( ClassesRetrieval.getDBpediaClasses());


About your implementation:

You are in the wrong path! It seems to me that you aren't writing code in the simplest way to achieve the expected behaviour. You are creating way to many maps in order to simply find a max number of intersections. 

I wouldn't put my hands on fire for it, because I can't test it, but I think that your code is equivalent to this:

public static void getNdMatches() throws IOException{
    List&lt;String&gt; dbpediaClasses = new ArrayList&lt;String&gt;( ClassesRetrieval.getdbpediaClasses());
    List&lt;String&gt; yagoClasses = new ArrayList&lt;String&gt;( ClassesRetrieval.fileToArrayListYago());
    HashMap&lt;String, Set&lt;String&gt;&gt; cachedYagos = new HashMap&lt;String, Set&lt;String&gt;&gt;();
    String yagoClassWithMaxMatches="";

    for(String dbClass:dbpediaClasses){
      int max = 0;
      Set&lt;String&gt; dbClassSet = Sets.newHashSet(GetDBpediaClassInstances(dbClass));
      for(String yagoClass:yagoClasses){
          Set&lt;String&gt; yagoSet = cachedYagos.get(yagoClass);
          if(yagoSet == null){
            yagoSet = Sets.newHashSet(GetYagooClassInstances(yagoClass);
            cachedYagos.put(yagoClass, yagoSet);
          }
          Set&lt;String&gt; IntersectionSet = Sets.intersection(dbClassSet, yagoSet);
          if(IntersectionSet.size() &gt; max){
            max = IntersectionSet.size();
            yagoClassWithMaxMatches = yagoClass
          }
      }
      if(max == 0){
          System.out.println(dbClass+" Corresponds to nothing");
      }else{
          System.out.println(dbClass+" Corresponds to "+ yagoClassWithMaxMatches+" with : "+max);
      }   
    }  
}