Skip to content

Commit ba90ee0

Browse files
author
Grzegorz Piwowarek
committed
Add code examples for Random List Element mini-article
1 parent fb5cc7d commit ba90ee0

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.baeldung;
2+
3+
import org.junit.Test;
4+
5+
import java.util.Arrays;
6+
import java.util.List;
7+
import java.util.Random;
8+
9+
public class RandomListElementTest {
10+
11+
@Test
12+
public void givenList_shouldReturnARandomElement1() throws Exception {
13+
List<Integer> givenList = Arrays.asList(1, 2, 3);
14+
Random rand = new Random();
15+
16+
Integer result = givenList.get(rand.nextInt(givenList.size()));
17+
}
18+
}

0 commit comments

Comments
 (0)