Count number of values of a list having same hash value in java?

Don’t know if I understand exactly what u want but if u want to find in that map how many records have a value u should use it like this :

public static void main(String[] args) {
    Map<String, List<String>> invertedindex = new HashMap<String, List<String>>();
    List<String> myList = new ArrayList<>();
    myList.add("firstitem");
    myList.add("seconditem");
    invertedindex.put("book", myList);
    invertedindex.put("book2", myList);
    int count_ = Collections.frequency(invertedindex.values(), myList);
    System.out.println(count_);
}

This will print 2.

Leave a Comment