title: Using a variable to select an array
body: <p>I am working on an android app project. I have an array which holds 55 words.  Each word within this array has another array of words which it will use if it is selected. My problem is that I do not know how to access the second array using a variable.</p>
  
  <p>Assuming I put the arrays within the java file and want to access the random array it might be something like:</p>
  
  <pre><code>    for (int i = 0; i &lt; variable_name.length; i++) {
          arrayList.add(variable_name[i]);    
      } 
  </code></pre>
  
  <p>this does not work.</p>
  
  <p>If I put the array into an XML file I would try to access it something like this:</p>
  
  <p>String[] some_array = getResources().getStringArray(R.array.variable_name);</p>
  
  <p>this does not work.</p>
  
  <p>While irrelevant to the discussion in Actionscript it would be done something like this:</p>
  
  <pre><code>      for (var a:int = 0; a &lt; this[variable_name+"Array"].length; a++){
             tempWordList[a] = this[variable_name+"Array"][a];
        }
  </code></pre>
  
  <p>One thing I should add is that the number of elements in the arrays accessed by a variable are not all the same.  e.g. some may have four while another may have six or seven.</p>
  
  <p>Thanks to the input below I was able to come up with a workable solution.  I am new to programing so this my not be the most efficient solution but it does work.</p>
  
  <pre><code>    String[] Words = { "zero", "one", "two" };
      String[][] otherWords = { { "green", "blue" }, { "orange", "red" }, { "yellow", "purple" } };
  
      for (int i = 0; i &lt; Words.length; i++) {
          if (Words[i] == targetWord) {
           arrayLocation = i;
          }
      }
      for (int i = 0; i &lt; otherWords[arrayLocation].length; i++) {
          String wordsToAdd = otherWords[arrayLocation][i];
          newWordList.add(wordsToAdd);
      }
  </code></pre>
  
  <p>If the string variable targetWord is equal to "one" the ArrayList newWordList will be equal to "orange" and "red"... </p>
  
  <p>Thanks again</p>