Obtaining an Array from an ArrayList

Posted on Updated on

While working with ArrayList we come to  a situation where we need actual array from arrayList.  Several reasons exist why we might want to convert a collection into an array such as…

  1. To integrate our collection based code to legacy code which doesn’t understand collection framework.
  2. To use a utility method which accept only array as parameter.
  3. To obtain faster processing times for certain operations.

Sample code 1

Output

Content of arrayList : [1, 2, 3, 4]
Sum : 10

Sample code 2.

Output

Content of arrayList : [1, 2, 3, 4]
Sum : 10

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.