HR자바 Java Iterator

개요[ | ]

HR자바 Java Iterator
해커랭크 Java
# 문제 비고
HR자바 Object Oriented Programming e
43 HR자바 Java Inheritance I
44 HR자바 Java Inheritance II
45 HR자바 Java Abstract Class
46 HR자바 Java Interface
47 HR자바 Java Method Overriding
48 HR자바 Java Method Overriding 2 (Super Keyword)
49 HR자바 Java Instanceof keyword
50 HR자바 Java Iterator

Java
Copy
import java.util.*;
public class Main{
   static Iterator func(ArrayList mylist){
      Iterator it=mylist.iterator();
      while(it.hasNext()){
Java
Copy
         Object element = it.next();
         if(element instanceof String)
Java
Copy
            break;
      }
      return it;
   }
   @SuppressWarnings({ "unchecked" })
   public static void main(String []args){
      ArrayList mylist = new ArrayList();
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int m = sc.nextInt();
      for(int i = 0;i<n;i++){
         mylist.add(sc.nextInt());
      }
      
      mylist.add("###");
      for(int i=0;i<m;i++){
         mylist.add(sc.next());
      }
      
      Iterator it=func(mylist);
      while(it.hasNext()){
         Object element = it.next();
         System.out.println((String)element);
      }
   }
}