0

I've got the following java problem: I need to find out which word has the biggest occurrence in a String. Example String:

String text = "Holy Diver is [...] band.";

what I've already done is:

String array[] = text.split("\\s");
Arrays.sort(array);

for (int i = 0; i < array.length; i++) {
    System.out.println(array[i]);
}

What I thought about:

for (int d = 0; d < array.length; d ++) {
    System.out.println(d);
    if (array[d].equals(array[++d])) {
        d--;
        System.out.println(d);  
        counter++;
        int[] e = new int[d];
    } else {
        counter = 0;
    }
}

Doesn't work for obvious reasons. I don't know if I am on the right way.

Nikolas Charalambidis
  • 40,893
  • 16
  • 117
  • 183
  • can you please give an example of your expected output and also what your method gives you – Seek Addo Sep 07 '16 at 16:33
  • Using a debugger will help – Jens Sep 07 '16 at 16:33
  • rather than this,I suggest to use map. put each word as key value as count.First check value or key is available,if available increase count from one.I am not satisfy with your approach. – Sanka Sep 07 '16 at 16:51

0 Answers0