title: java,Arraylist,morse code
body: <p>I have task to code a morse code converter in java. I input words and it converts them to morse code.</p>
  
  <p>I should not use <code>HashMap</code> or <code>HashSet</code>. I can use <code>ArrayList</code>. I wrote it but I have error. Can you help me, pls </p>
  
  <p><strong>The Error:</strong></p>
  
  <pre><code>Exception in thread "main" java.lang.ExceptionInInitializerError
  Caused by: java.lang.IndexOutOfBoundsException: Index: 65, Size: 0
      at java.base/java.util.ArrayList.rangeCheckForAdd(ArrayList.java:685)
      at java.base/java.util.ArrayList.add(ArrayList.java:494)
      at com.company.Main.&lt;clinit&gt;(Main.java:25)
  </code></pre>
  
  <p><strong>The code:</strong></p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.List;
  
  public class Main{
  
      final static String[][] code = {
              {"A", ".-     "}, {"B", "-...   "}, {"C", "-.-.   "}, {"D", "-..    "},
              {"E", ".      "}, {"F", "..-.   "}, {"G", "--.    "}, {"H", "....   "},
              {"I", "..     "}, {"J", ".---   "}, {"K", "-.-    "}, {"L", ".-..   "},
              {"M", "--     "}, {"N", "-.     "}, {"O", "---    "}, {"P", ".--.   "},
              {"Q", "--.-   "}, {"R", ".-.    "}, {"S", "...    "}, {"T", "-      "},
              {"U", "..-    "}, {"V", "...-   "}, {"W", ".-   - "}, {"X", "-..-   "},
              {"Y", "-.--   "}, {"Z", "--..   "}, {"0", "-----  "}, {"1", ".----  "},
              {"2", "..---  "}, {"3", "...--  "}, {"4", "....-  "}, {"5", ".....  "},
              {"6", "-....  "}, {"7", "--...  "}, {"8", "---..  "}, {"9", "----.  "},
              {"'", ".----. "}, {":", "---... "}, {",", "--..-- "}, {"-", "-....- "},
              {"(", "-.--.- "}, {".", ".-.-.- "}, {"?", "..--.. "}, {";", "-.-.-. "},
              {"/", "-..-.  "}, {"-", "..--.- "}, {")", "---..  "}, {"=", "-...-  "},
              {"@", ".--.-. "}, {"\"", ".-..-."}, {"+", ".-.-.  "}, {" ", "/"}};
      final static List&lt;String&gt; ascii = new ArrayList&lt;String&gt;();
  static {
      for (String[] pair : code){
          ascii.add(pair[0].charAt(0), pair[1].trim());
      }
  }
      public static void main(String[] args){
          printMorse("   Hello     World!");
      }
      static void printMorse(String input) {
          System.out.printf("%s %n", input);
  
          input = input.trim().replaceAll("[ ]+", " ").toUpperCase();
          for (char c : input.toCharArray()) {
              String s = ascii.get(c);
              if (s != null){
                  System.out.printf("%s ", s);
              }
          }
          System.out.println("\n");
      }
  
  }
  </code></pre>