Enter your E-mail Address below for Free E-mail Alerts right Into your Inbox: -

Sunday

How to convert Java Object Array to List in Java

How to convert Java Object Array to List in Java

We studied how to create a Array, how to sort it etc. Now we are going to convert the Array to List .

Example:

public final class Test {

static String[] strArray = new String[10];

    public static void main(String args[])
    {
    strArray[0]="abc";
    strArray[1]="def";
    strArray[2]="ghi";
    strArray[3]="jkl";
    strArray[4]="mno";
   
    List list = Arrays.asList(strArray);
    Iterator li = list.iterator();
    while(li.hasNext())
    {
    System.out.println(li.next());
    }
    }
 
}

No comments:

Post a Comment