Search Java Programs

Wednesday, January 20, 2010

String Array to Collection Example

Array to Collection example.This example shows you how to Convert string array to Collection.


This example shows you how to Convert string array to an Collection.

Here is the code

 /**
* @ # StringArray3.java
* A class repersenting how Convert
* string array to a collection
* version 04 June 2008
* author Rose India
*/

import java.util.*;
public class StringArray3 {
public static void main(String args[]){
String arr[] = {"Zero", "One", "Two"};

//Convert string array to a collection
Collection l = Arrays.asList(arr);
ArrayList list = new ArrayList(l);

System.out.println("list = " + list);
}
}
Output
list = [Zero, One, Two]

No comments:

Post a Comment

Website Design by Mayuri Multimedia