title: Converting List of objects to an Array of Strings
body: <p>In my main class, I have: <code>List&lt;Person&gt; allPeople = new ArrayList&lt;&gt;();</code></p>
  
  <p>Then in the class I have a method which returns a String array of all the <code>Id</code> of people (Person has an accessor method <code>getId()</code> ). </p>
  
  <p>What is the prettiest way to convert the list to an array with just the Ids as String? </p>
  
  <p>This is my current solution:</p>
  
  <pre><code>public String[] getAllId() {
  
      Object[] allPeopleArray = allPeople.toArray();
      String allId[] = new String[allPeople.size()];              
  
      for(int i=0; i&lt;=allPeople.size()-1; i++){
          allId[i] = ((Person)allPeopleArray [i]).getId();                    
      }
  
      return allId;
  }
  </code></pre>
  
  <p>Above works, but is there a 'better' way to do this? </p>