Sunday, March 31, 2013

Collection to Array



package com.swain.cell;

import java.util.ArrayList;
import java.util.List;

public class CollectionToArray {

       public static void main(String[] args) {
              List list = new ArrayList();
              list.add("This ");
              list.add("is ");
              list.add("a ");
              list.add("good ");
              list.add("program.");
              Object[] s1 = list.toArray(new String[0]);
              for (int i = 0; i < s1.length; ++i) {
                     String contents = (String) s1[i];
                     System.out.print(contents);
              }
       }

}

No comments:

Post a Comment

How ChatGPT can Benefit Coding: Your Guide to Leveraging an AI Language Model

 Introduction: Hello, coders! Welcome to this blog post on how ChatGPT, an AI language model, can benefit your coding skills and projects. A...