We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
importjava.util.*;publicclassMain{staticIteratorfunc(ArrayListmylist){Iteratorit=mylist.iterator();while(it.hasNext()){Objectelement=it.next();if(elementinstanceofString)//Hints: use instanceof operatorbreak;}returnit;}@SuppressWarnings({"unchecked"})publicstaticvoidmain(String[]args){ArrayListmylist=newArrayList();Scannersc=newScanner(System.in);intn=sc.nextInt();intm=sc.nextInt();for(inti=0;i<n;i++){mylist.add(sc.nextInt());}mylist.add("###");for(inti=0;i<m;i++){mylist.add(sc.next());}Iteratorit=func(mylist);while(it.hasNext()){Objectelement=it.next();System.out.println((String)element);}}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java Iterator
You are viewing a single comment's thread. Return to all comments →