Merge pull request #623 from eugenp/grzegorz_random_list_element

Add code examples for Random List Element mini-article
This commit is contained in:
Alex Theedom 2016-08-22 18:27:47 +01:00 committed by GitHub
commit f99f6d962f
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()));
}
}