Sunday, March 31, 2013

Array to Collection



package com.swain.cell;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;

public class ArrayToCollection {
       public static void main(String args[]) throws IOException {
              BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
              System.out.println("How many elements you want to add to the array: ");
              int n = Integer.parseInt(in.readLine());
              String[] name = new String[n];
              for (int i = 0; i < n; i++) {
                     name[i] = in.readLine();
              }
              List list = Arrays.asList(name);
              System.out.println();
              for (Object li : list) {
                     String str = (String) li;
                     System.out.print(li + " ");
              }
       }

}

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...