diff --git a/core-java-8/src/test/java/com/baeldung/RandomListElementTest.java b/core-java-8/src/test/java/com/baeldung/RandomListElementTest.java new file mode 100644 index 0000000000..4f0ba466ea --- /dev/null +++ b/core-java-8/src/test/java/com/baeldung/RandomListElementTest.java @@ -0,0 +1,18 @@ +package com.baeldung; + +import org.junit.Test; + +import java.util.Arrays; +import java.util.List; +import java.util.Random; + +public class RandomListElementTest { + + @Test + public void givenList_shouldReturnARandomElement1() throws Exception { + List givenList = Arrays.asList(1, 2, 3); + Random rand = new Random(); + + Integer result = givenList.get(rand.nextInt(givenList.size())); + } +}