Add code examples for Random List Element mini-article

This commit is contained in:
Grzegorz Piwowarek 2016-08-21 11:51:10 +02:00
parent fb5cc7dcf9
commit ba90ee0a2f
1 changed files with 18 additions and 0 deletions

View File

@ -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<Integer> givenList = Arrays.asList(1, 2, 3);
Random rand = new Random();
Integer result = givenList.get(rand.nextInt(givenList.size()));
}
}