How will you convert an ArrayList to Arrays?

Answers were Sorted based on User's Feedback



How will you convert an ArrayList to Arrays?..

Answer / vikneswarank

Using toArray() method for example

ArrayList arr_obj=new ArrayList()
arr_obj.add("viki");
arr_obj.add("siva");

Object[] obj=arr_obj.toArray();

for further Detail go to my website :
http://www.beexpert.co.in/

Is This Answer Correct ?    11 Yes 2 No

How will you convert an ArrayList to Arrays?..

Answer / tapan kumar kundu

Using toArray() method for example

ArrayList arr_obj=new ArrayList()
arr_obj.add("viki");
arr_obj.add("siva");

Object[] obj=arr_obj.toArray();

for further Detail go to my website :
http://www.beexpert.co.in/

Is This Answer Correct ?    6 Yes 0 No

How will you convert an ArrayList to Arrays?..

Answer / 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

How will you convert an ArrayList to Arrays?..

Answer / ramesh

ArrayList arr_obj=new ArrayList()
arr_obj.add("viki");
arr_obj.add("siva");

Object[] obj=arr_obj.toArray();

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More Core Java Interview Questions

What is use of set in java?

0 Answers  


How the threads are synchronized?

2 Answers   BMC, CTS,


What is append in java?

0 Answers  


Explain about automatic type conversion in java?

0 Answers  


ublic class Java_Coding_Samples { public static void JavaHungr(NumberFormatException ae){ System.out.println("integer"); } public static void JavaHungry(Exception e){ System.out.println("string"); } public static void JavaHungry(ArithmeticException ae){ System.out.println("object"); } public static void main(String[] args) { JavaHungry(null); }

1 Answers  


What is java string pool?

0 Answers  


What are the rules for naming an array?

0 Answers  


Is there any limitation of using inheritance?

0 Answers  


How do you print array in java?

0 Answers  


Explain jdk, jre and jvm?

0 Answers  


What is comparable and comparator interface? List their differences

0 Answers  


What is an interface in java? Explain

0 Answers  


Categories