-2

Possible Duplicate:
How to store arrayList into an array in java?

I want to know how can I convert an ArrayList into an Array.

Is there any method to do so in Java?

Can anyone help me about this?

0

2 Answers 2

7

yep, there is check out the List API:

List.toArray(T[])

Example:

List<Integer> list = new ArrayList<>();
list.add(1);
list.add(2);
list.add(3);
Integer[] arr = list.toArray(new Integer[list.size()]);
Sign up to request clarification or add additional context in comments.

2 Comments

I need to get results from a ResultSet in an Array after converting the ArrayList to Array. How to do so?
iterate over your result set, populate the arraylist and then convert it into the array appriately as shown in the answer.
0

There is the .toArray() function for an array list that should accomplish that.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.