As salamo alaikum wa rahmatullah
package collections.demo;
import java.util.ArrayList;
import java.util.Scanner;
public class ArrayListDemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
ArrayList<String> aList=new ArrayList<String>();
Scanner sc=new Scanner(System.in);
for(int i=0; i<=5;i++) {
System.out.println("Enter the string for Array List");
String str=sc.nextLine();
aList.add(str);
}
// printing element
System.out.println("Element is Array List"+aList);
// fetching element using for loop
for(int i=0; i<aList.size(); i++) {
System.out.println("Element : -"+aList.get(i));
}
}
}
Jazak allah khair
No comments:
Post a Comment