title: How to find the second most frequent character in java?
body: <p>What I am trying to achieve is, when there is a given word, I need to find out the second most frequent character within that string.</p>
  <p>In additions to that, there is some more options I want to achieve. For example,</p>
  <ol>
  <li><p>If a string, &quot;ababababd&quot; is given, there are <strong>four</strong> '<strong>a</strong>'s, <strong>four</strong>  '<strong>b</strong>'s, and <strong>one</strong> '<strong>d</strong>', so in this case, I need to printout '<strong>d</strong>'.</p>
  </li>
  <li><p>If a string is &quot;ababababdc&quot; is given, there are <strong>four</strong>  '<strong>a</strong>'s, <strong>four</strong>  '<strong>b</strong>'s, <strong>one</strong> '<strong>d</strong>' <strong>and</strong> '<strong>c</strong>', I need to printout '<strong>dc</strong>'</p>
  <pre><code>public class MemorizeWorld {
      public static void main(String[] args) {
      Solution solution = new Solution();
      String a = &quot;ababababd&quot;;
      solution.solution(a);
   }
  }
  
  class Solution {
       public void solution(String a) {
           int[] array = new int[26];
           char[] char_array = a.toCharArray();
  
           for(int i = 0; i &lt; char_array.length; i++) {
               int index = char_array[i] - 'a';
               array[index]++;
           }
           int max = 0;
           for(int i = 0; i &lt; array.length; i++) {
               if(array[i] &gt; max) {
                   max = array[i];
               }
           }
       }
   }
  </code></pre>
  </li>
  </ol>
  <p>This is what I have done so far and I am stuck on getting a solution. I know how to get the second most frequent character by following the post from geeksforgeeks, but I don't know how I should apply those two options above to that. Is there anyone who can help me with this problem?</p>