Sunday, 1 June 2014

ArrayList : toArray() : get the List Data as object Array

public Object[] toArray()
Returns an array containing all of the elements in this list in proper sequence. The returned array is totally independent, Updating the Array won't affect List.

import java.util.*;
class ArrayListToObjectArray{
 public static void main(String args[]){
  ArrayList<Float> myList = new ArrayList<> ();
  
  /* Add Elements to myList */
  myList.add(10.01f);
  myList.add(123.01f);
  myList.add(321.01f);
  myList.add(456.78f);
  
  Object myArr = myList.toArray();
  
  System.out.println("Elements in the Array are");
  for(Float f1 : myList)
   System.out.println(f1);
 }
}

Output
Elements in the Array are
10.01
123.01
321.01
456.78


Prevoius                                                 Next                                                 Home

No comments:

Post a Comment