HomeCode HereJava collections and errors quiz Java collections and errors quiz Admin 1 min read Updated November 16, 2026 Nine questions on ArrayList, HashMap, exceptions, generics and file reading. Java Java collections and errors quiz 9 questions, instant feedback Question 1 of 9 What is the difference between an array and an ArrayList? A ArrayList can grow B Arrays hold objects only C ArrayList cannot be indexed D Arrays are slower to read An ArrayList resizes as items are added. An array's length is fixed at creation. Question 2 of 9 Which method adds to an ArrayList? A push B add C append D insert add appends or inserts at an index. push exists on Deque, not List. Question 3 of 9 What does a HashMap store? A Ordered pairs B Key-value pairs with no guaranteed order C Only strings D Duplicate keys HashMap maps unique keys to values. Use LinkedHashMap or TreeMap when order matters. Question 4 of 9 What does map.get(key) return for a missing key? A An exception B null C 0 D An empty string get returns null when the key is absent. getOrDefault is the safer form when a default makes sense. Question 5 of 9 Which exception must be caught or declared? A RuntimeException B Checked exceptions C Error D NullPointerException Checked exceptions are part of the method signature. Unchecked exceptions and errors do not require handling. Question 6 of 9 What is the purpose of finally? A To run code whether or not an exception occurred B To hide an exception C To rethrow an exception D To declare a checked exception finally runs on both paths, which is where cleanup such as closing a reader belongs. Question 7 of 9 What does a generic type parameter such as List give you? A Faster execution B Compile-time type checking C Automatic sorting D Null safety Generics move type errors to compile time. At runtime the type information is mostly erased. Question 8 of 9 Which class reads a text file line by line? A FileOutputStream B BufferedReader C PrintWriter D RandomAccessFile BufferedReader wraps a Reader and offers readLine. FileOutputStream is for bytes. Question 9 of 9 What is the modern way to ensure a file is closed? A Call close in finally B try-with-resources C A finalizer D System.exit try-with-resources closes anything implementing AutoCloseable automatically, even when an exception is thrown. Check my answers Try again Your answers stay in this browser. Nothing is sent to a server. More quizzes Java getting started quiz Coming soon Java control flow quiz 9 questions Java methods and objects quiz 9 questions All quizzes