Monday, 7 May 2012

String Array to Collection Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
 */
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

Related Posts Plugin for WordPress, Blogger...