title: what is the time complexity for copying list back to arrays and vice-versa in Java?
body: <p>I am wondering what is the time complexity [in big <code>O(n)</code> notations] of  <code>ArrayList</code> to <code>Array</code> conversion:</p>
  
  <pre><code>ArrayList assetTradingList = new ArrayList();
  assetTradingList.add("Stocks trading");
  assetTradingList.add("futures and option trading");
  assetTradingList.add("electronic trading");
  assetTradingList.add("forex trading");
  assetTradingList.add("gold trading");
  assetTradingList.add("fixed income bond trading");
  String [] assetTradingArray = new String[assetTradingList.size()];
  assetTradingArray.toArray(assetTradingArray);
  </code></pre>
  
  <p>similarly, what is the time complexity for arrays to list in the following ways:</p>
  
  <p>method 1 using <code>Arrays.asList</code>:</p>
  
  <pre><code>String[] asset = {"equity", "stocks", "gold", "foreign exchange","fixed
      income", "futures", "options"};
  List assetList = Arrays.asList(asset);
  </code></pre>
  
  <p>method 2 using <code>collections.addAll</code>:</p>
  
  <pre><code>    List assetList = new ArrayList();
      String[] asset = {"equity", "stocks", "gold", "foreign exchange", "fixed
          income", "futures", "options"};
      Collections.addAll(assetList, asset);
  </code></pre>
  
  <p>method 3 <code>addAll</code>:</p>
  
  <pre><code>     ArrayList newAssetList = new ArrayList();
       newAssetList.addAll(Arrays.asList(asset));
  </code></pre>
  
  <p>The reason I am interested in the overhead of copying back and forth is because in typical interviews, questions come such as <code>given an array of pre-order traversal elements, convert to binary search tree</code> and so on, involving <code>arrays</code>. With <code>List</code> offering a whole bunch of operations such as <code>remove</code> etc, it would make it simple to code using <code>List</code> than <code>Array</code>.</p>
  
  <p>In which case, I would like to defend me for using <code>list</code> instead of <code>arrays</code> saying "I would first convert the Array to List because the overhead of this operation is not much (hopefully)".</p>
  
  <p>Any better methods recommended for copying the elements back and forth from <code>array to list</code> that would be faster would be good know too.</p>
  
  <p>Thanks</p>