how-to

Math

How to choose random array item

For working with Random class you need to use:

import java.util.Random;

We have this String Array:

String[] COLORS_TYPES = { "Black", "Yellow", "White", "Red", "Silver" };

For choosing of randon item use this code:

Random random = new Random();

System.out.println( COLORS_TYPES[ random.nextInt( COLORS_TYPES.length ) ] );

One selected item is written.