import java.util.*;\npublic class Example{\n\n public static void main(String []args){\n ArrayList mylist = new ArrayList();\n mylist.add(\"Hello\");\n mylist.add(\"Java\");\n mylist.add(\"4\");\n Iterator it = mylist.iterator();\n while(it.hasNext()){\n Object element = it.next();\n System.out.println((String)element);\n }\n }\n}<\/code><\/pre>\n\n\n\nIn this problem you need to complete a method func. The method takes an ArrayList as input. In that ArrayList there is one or more integer numbers, then there is a special string “###”, after that there are one or more other strings. A sample ArrayList may look like this:<\/p>\n\n\n\n
element[0]=>42\nelement[1]=>10\nelement[2]=>\"###\"\nelement[3]=>\"Hello\"\nelement[4]=>\"Java\"<\/code><\/pre>\n\n\n\nYou have to modify the func method by editing at most 2 lines so that the code only prints the elements after the special string “###”. For the sample above the output will be:<\/p>\n\n\n\n
Hello\nJava<\/code><\/pre>\n\n\n\nNote: The stdin doesn’t contain the string “###”, it is added in the main method.<\/p>\n\n\n\n
To restore the original code in the editor, click the top left icon on the editor and create a new buffer.<\/p>\n\n\n\n
<\/span>Solution – Java Iterator<\/strong><\/span><\/h2>\n\n\n\nimport java.util.*;\npublic class Main{\n \n static Iterator func(ArrayList mylist){\n Iterator it=mylist.iterator();\n while(it.hasNext()){\n import java.util.*;\npublic class Main{\n\t\n static Iterator func(ArrayList mylist){\n Iterator it=mylist.iterator();\n while(it.hasNext()){\n Object element = it.next();\n if(element instanceof String)\/\/Hints: use instanceof operator\n\n\t\t\tbreak;\n\t\t}\n return it;\n \n }\n @SuppressWarnings({ \"unchecked\" })\n public static void main(String []args){\n ArrayList mylist = new ArrayList();\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int m = sc.nextInt();\n for(int i = 0;i<n;i++){\n mylist.add(sc.nextInt());\n }\n \n mylist.add(\"###\");\n for(int i=0;i<m;i++){\n mylist.add(sc.next());\n }\n \n Iterator it=func(mylist);\n while(it.hasNext()){\n Object element = it.next();\n System.out.println((String)element);\n }\n }\n}\n\n break;\n }\n return it;\n \n }\n @SuppressWarnings({ \"unchecked\" })\n public static void main(String []args){\n ArrayList mylist = new ArrayList();\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int m = sc.nextInt();\n for(int i = 0;i<n;i++){\n mylist.add(sc.nextInt());\n }\n \n mylist.add(\"###\");\n for(int i=0;i<m;i++){\n mylist.add(sc.next());\n }\n \n Iterator it=func(mylist);\n while(it.hasNext()){\n Object element = it.next();\n System.out.println((String)element);\n }\n }\n}<\/pre>\n\n\n\n