Java Random nextBytes() MethodThe nextBytes() method of Random class places the generated random bytes into an user-supplied byte array. SyntaxParametersHere the parameter 'bytes' is the byte array which is to be filled with random bytes. ThrowsThe nextBytes() method throws NullPointerException if the byte array is null. Example 1Test it NowOutput: Random bytes = ( -30 74 11 124 41 -54 105 84 125 -90 ) Example 2Test it NowOutput: Error:(9, 44) java: 'void' type not allowed here Note: The nextBytes() method has a void return type and 'void' type are not allowed in system.out.println() function.Example 3Test it NowOutput: Exception in thread "main" java.lang.NullPointerException atjava.util.Random.nextBytes(Random.java:228) at com.javaTpoint.JavaRandomNextBytesExample3.main(JavaRandomNextBytesExample3.java:7)
Next TopicJava Random
|