How will you convert an ArrayList to Arrays?

Answer Posted / vikas

using toArray() method.
example:

ArrayList<Integer> al = new ArrayList<Integer>();
al.add(1);
al.add(5);
al.add(8);
al.add(10);

//Get the array
Integer tempArray = new Integer[al.size()];
tempArray = al.toArray(tempArray);

Is This Answer Correct ?    7 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Give differences between Quicksort &Mergesort. When should these sorts be used andwhat is their running time in java?

672


Why enumeration is faster than iterator?

524


Why declare Main() inside the class in java ?

604


Which of the following classes will have more memory allocated?

577


Which is better list or arraylist in java?

485






What is square root in java?

582


what is a green thread? : Java thread

567


What is a function easy definition?

521


What are the common uses of "this" keyword in java ?

565


Can a class declared as private be accessed outside it’s package?

508


What is object class in java?

497


Howto get an object that will perform date & time calculations then format it for output in some different locales with different date style.can ne1 tel me the answer of this question.pls

1442


For class CFoo { }; what default methods will the compiler generate for you>?

606


Does java vector allow null?

530


Why is core java important?

570