To convert array based data into list / collection based we can use java.util.Arrays class. This class provide a static method asList(Object[] a) that converts array into list / collection. The result of our code is:
import java.util.Arrays;
import java.util.List;
import java.util.Iterator;
public class ArraysExample
{
public static void main(String[] args)
{
String[] array = {"Happy", "New", "Year", "2006"};
List list = Arrays.asList(array);
Iterator iterator = list.iterator();
while (iterator.hasNext())
{
System.out.println((String) iterator.next());
}
}
}
Happy
New
Year
2006
Click Here to See Answer .....
Subscribe to my RSS feed and get more JAVA Question, and Guideline, Plus a lot more great advice to help your Software Career.
0 comments:
Post a Comment