As salamo alaikum wa rahmatullah
package collections.demo;
import java.util.LinkedList;
import java.util.Scanner;
public class LinkedListDemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
LinkedList<String> lList=new LinkedList<String>();
Scanner sc=new Scanner(System.in);
for(int i=0;i<=5;i++) {
System.out.println("Enter the string for Linked List");
String name=sc.nextLine();
lList.add(name);
}
System.out.println(lList);
// iterating data
for(int j=0; j<lList.size();j++) {
System.out.println("Element of Linked List - "+lList.get(j));
}
}
}
Jazak allah khair
No comments:
Post a Comment