This java example will demonstrate how to initialize a primitive or object array of specified type and size while using java and guava.
Straight up Java
Java core library provides two basic ways to initialize an array. First is to create an array with the new operator then assign a value to each element of the array. The second is to use the shortcut syntax to create and initialize an array.
Initialize primitive array
Initialize primitive array shortcut
Initialize object array
Initialize object array shortcut
ObjectArrays is a guava utility class that pertains to object arrays. In first example below, we will call the ObjectArrays.newArray method which will return a new array of the specified length and component type. The second example will call the overloaded ObjectArrays.newArray which will return a new array of the the given length and a reference type. In this case returning a String.