New course! Every coder should learn Generative AI!
Try a free lesson0
How to get upto 20 more names of people as input if user wants to add more names or stop and store them in the list? Thank you
import java.util.*; class simple { public static void main(String args[]) { ArrayList<String> al=new ArrayList<String>(); Scanner ac=new Scanner(System.in); al.add(ac.next()); Iterator itr=al.iterator(); while(itr.hasNext()) { System.out.println(itr.next()); } } }
1 Answer
0
Scanner sc=new Scanner (System.in);
ArrayList<String> al=new ArrayList<String>();
while(sc.hasNext())
al.add(sc.next());
System.out.println(al);