I want to create a nested HashMap which returns the frequency of terms among multiple files. Like,
Map<String, Map<String, Integer>> wordToDocumentMap=new HashMap<>();
I have been able to return the number of times a term appears in a file.
  Map<String, Integer> map = new HashMap<>();//for frequecy count       
   String str = "Wikipedia is a free online encyclopedia, created and edited by 
     volunteers around the world."; //String str suppose a file a.java
    // The query string
    String query = "edited Wikipedia volunteers";
    // Split the given string and the query string on space
    String[] strArr = str.split("\\s+");
    String[] queryArr = query.split("\\s+");
    // Map to hold the frequency of each word of query in the string
    Map<String, Integer> map = new HashMap<>();
    for (String q : queryArr) {
        for (String s : strArr) {
            if (q.equals(s)) {
                map.put(q, map.getOrDefault(q, 0) + 1);
            }
        }
    }
    // Display the map
    System.out.println(map);
In my code its count the frequency of the given query Individually. But I want to Map the query term and its frequency with its filenames. I have searched around the web for a solution but am finding it tough to find a solution that applies to me. Any help would be appreciated!
 
    