title: Why is keyword 's' giving me an error?
body: <p>I have the following method which gives me an error when the word is "sk" but not when it is "ks". These keywords are coming from the arrPunjabi.</p>
  
  <pre><code>Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 7
  at StringTes.main(StringTes.java:51)
  
  HashSet&lt;String&gt; all = new HashSet&lt;String&gt;();
      String[] arrPunjabi = {"d b a b s k s", "d t r p n d k h"};
      String[] arrGurmukhi = {"fMfauiq bMdn Aink bwr srb klw smrQ ]", "foln qy rwKhu pRBU nwnk dy kir hQ ]1]"};
      ArrayList&lt;String&gt; arr = new ArrayList&lt;String&gt;();
      String word = "sk";
      char[] wordArr = word.toCharArray();
      for(int i = 0; i&lt; arrPunjabi.length;i++){
          String[] words = arrPunjabi[i].split("\\s+");
          //word[] = {d, b, a, b, s, k, s};
       if (word.length() == 2){
              for(int j = 0; j &lt; words.length; j++){
                  if(words[j].startsWith(""+wordArr[0]) &amp;&amp; words[j+1].startsWith(""+wordArr[1])){   //this is where I am getting an error.
                      arr.add(arrGurmukhi[i]);
                      all.addAll(arr);
                      arr.clear();
                      arr.addAll(all);
                  }
              }
          }
  
      }
      System.out.println(arr);
  </code></pre>