I would like to ask how can I find the most frequent element in a 2D **String** array and also the number of occurrences this element has in Java?

More specifically:

```java
public static void mostFrequentElement(String[][] data) {
    // What should I write here?
}

```

```java
String[][] data = {
        {"apple", "orange", "orange"},
        {"grape", "orange", "melon"},
};

mostFrequentElement(data);
// The function prints "orange 3" in the console
// This is because "orange" is the most frequent
// element in the data array and it showed up 3 times

```

I tried using `HashMap`, but I got confused with it since I'm a beginner to Java. Thank you very much!