java4all@1986 java. Powered by Blogger.

Convert a List (ArrayList) to an Array with zero length array

>> Monday, May 23, 2011

For this we use toArray() method.
import java.util.ArrayList;
import java.util.List;

public class Main {
public static void main(String[] args) {
List carList = new ArrayList();

carList.add("A");
carList.add("B");
carList.add("C");
carList.add("D");

String[] carArray = carList.toArray(new String[0]);

for (String car : carArray) {
System.out.println(car);
}
}
}


o/p:

/*
A
B
C
D
*/

0 comments:

Post a Comment

FaceBook Login

HTML/JAVASCRIPT

HTML/JAVASCRIPT

HTML/JAVASCRIPT

HTML/JAVASCRIPT

Total Pageviews

STATCOUNTER

  © Blogger template Simple n' Sweet by Ourblogtemplates.com 2009

Back to TOP