public static Object instantiatePrimitiveArray ( Class < ? > type , String [ ] values ) { logger . entering ( new Object [ ] { type , values } ) ; validateParams ( type , values ) ; checkArgument ( isPrimitiveArray ( type ) , type + " is NOT a primitive array type." ) ; Class < ? > componentType = type . getComponentType ( ) ; Object arrayToReturn = Array . newInstance ( componentType , values . length ) ; Method parserMethod = getParserMethod ( componentType ) ; for ( int i = 0 ; i < values . length ; i ++ ) { try { Array . set ( arrayToReturn , i , parserMethod . invoke ( arrayToReturn , values [ i ] ) ) ; } catch ( ArrayIndexOutOfBoundsException | IllegalArgumentException | IllegalAccessException | InvocationTargetException e ) { throw new ReflectionException ( e ) ; } } logger . exiting ( arrayToReturn ) ; return arrayToReturn ; }
This helper method facilitates creation of primitive arrays and pre - populates them with the set of String values provided .