banner Test 18

Test 18 - Free Java SE 25 certification Mock test - Exam Code 1Z0-831-Oracle certified Java SE 25 Professional

Arrays and Lists store the bulk of the data in most day to day Java programs so the 1Z0-831 exam tests them pretty thoroughly. This free Java SE 25 mock test covers array creation and manipulation as well as the List interface, giving you the chance to practice with the details that will determine whether a piece of code will compile, run or fail.

You start off with arrays. The questions will use all the different declaration styles (int[] a, int a[] etc) and will ask you all sorts of things about default values, lengths and printed output. Array covariance comes up all the time (you can assign a String[] to an Object[] and it will compile, but if you then try to store an Integer in it you'll get an ArrayStoreException at runtime). You'll also use all the various Array methods (Arrays.toString, deepToString, copyOf, copyOfRange, fill, equals, mismatch and sort) and need to know exactly what each one returns and which ones will mutate their input.

Searching raises the classic trap. Arrays.binarySearch only produces a meaningful result on sorted data and the value it returns for a missing element is a negative insertion point minus one. You'll work that value out in a number of the items as the arithmetic is easy to get wrong under pressure.

Lists come next. You're going to be comparing ArrayList and LinkedList and then testing add, addAll, remove, set, get, indexOf, subList, replaceAll, removeIf and sort. A key gotcha is remove on a List of Integer where an int will remove by index and an Integer will remove by value. You'll also be looking at the differences between List.of (which is immutable and won't accept nulls), Arrays.asList (a fixed size view backed by an array) and the copy returned by List.copyOf. Certain operations on these lists will throw an UnsupportedOperationException and you'll need to know when that happens.

Iteration and conversion complete the picture. You'll be looking at questions on toArray, on iterating with a ListIterator in both directions and on ConcurrentModificationException if you're changing a list during a loop. Generics come into play with arrays too in that you can't create a generic array and a varargs parameter of a parameterised type will give you a warning. Those are the easy ones once you remember that generic types are erased at runtime.

Every explanation explicitly shows the state of the array/list after each operation. Do the test, go through all your misses and in a scratch file reproduce the list behaviours that tripped you up. That way your memorised warnings become instinct and that's precisely what you need on exam day.

Welcome to your Free Java SE 25 – Test 18