ArrayList - String read and display


// ArrayList
// Strings

/*
Write a java program which stores the list of strings in an ArrayList and then displays the contents of the list.
*/

// ArrayList

import java.util.*;

class AL_Str
{
     public static void main(String as[])
     {
          ArrayList <String>al = new ArrayList<String>();
          Scanner s = new Scanner(System.in);
         
          System.out.print("Enter number of strings : ");
          int N = s.nextInt();
         
          for(int i=0;i<N;i++)
          {
              System.out.print("Enter string : "); 
              String str = s.next();
              al.add(str);
          }
         
          System.out.println("Elements in ArrayList are : "+al);
     }
}





No comments:

Post a Comment

Don't be a silent reader...
Leave your comments...

Anu