title: android: string arrays (copy all or select from another string array with criteria)
body: <h1>Situation:</h1>
  
  <p>I have a string array in the resource, which consists of all types of, say, questions. </p>
  
  <p>If user clicks for All types, for example, to select all, then the <code>selection_question</code> string array would copy all the items in <code>all_question</code>.</p>
  
  <p>Yet if user clicks for a specific type of questions, say, to select just animal related questions, then the <code>selection_question</code> string array would copy all the items in <code>all_question</code> that contains "animals" this word.</p>
  
  <p>My code is as simple as follows:</p>
  
  <p><strong>declare:</strong></p>
  
  <pre><code>String[] all_Question ;
  String[] selection_Question;
  </code></pre>
  
  <p><strong>OnCreate:</strong></p>
  
  <pre><code>all_Question = getResources().getStringArray(R.array.all_Q_List); 
  all_numberofquestions = all_Question.length;
  
  // reset 
  selection_numberofquestions = 0;
  selection_Question = new String[0];
  j =0;
  </code></pre>
  
  <p><strong>if to select all:</strong></p>
  
  <pre><code>for (int i = 0; i &lt; all_numberofquestions ; i++) 
  {
      selection_Question[i] = all_Question [i];
  }
  </code></pre>
  
  <p><strong>if to select based on some criteria:</strong></p>
  
  <pre><code>for (int i = 0; i &lt; all_numberofquestions ; i++) 
  {
      if (all_Question [i].contains("animal"))
      {
          selection_Question [j] = all_Question [i];
          j++;
      }
  }
  </code></pre>
  
  <h1>Question:</h1>
  
  <p>It then popups with the following error as shown in Logcat:</p>
  
  <pre><code>03-04 22:14:10.568: E/AndroidRuntime(24917): Caused by: java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
  </code></pre>
  
  <p>I does not understand why it is Out of Bounds? How could the above codes be modified?</p>
  
  <p>Thanks!!</p>