Merge pull request #623 from eugenp/grzegorz_random_list_element
Add code examples for Random List Element mini-article
This commit is contained in:
commit
f99f6d962f
|
@ -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()));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue