Shuffle(repeatable) a List
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Random;
public class Main {
public static void main(String args[]) {
String simpsons[] = { "Bart", "Hugo", "Lisa", "Marge", "Homer",
"Maggie", "Roy" };
List list1 = Arrays.asList(simpsons);
List list2 = Arrays.asList(simpsons);
Random rand = new Random(100);
Collections.shuffle(list1, rand);
Collections.shuffle(list2, rand);
System.out.println(list1);
System.out.println(list2);
}
}
Output:
[Maggie, Marge, Bart, Homer, Lisa, Hugo, Roy]
[Maggie, Marge, Bart, Homer, Lisa, Hugo, Roy]
Home
Java Book
Runnable examples
Java Book
Runnable examples
Collection List:
- Create a list from an array
- Add element to a list at specified index
- Append one list to another list
- Insert a list at Specified Index
- Compare two List objects
- Convert Collection to List
- Convert a Queue to a List
- Convert List to array
- Convert List to a Set
- Copy List to Vector
- Copy one List to Another List
- Fill all elements in a list
- Fill n Copies of Specified Object
- Find maximum element in a List
- Find Minimum element in a List
- Get element by index
- Get Enumeration over List
- Get Synchronized List from a List
- Get Sub List
- Loop a list by Iterator
- Loop a list by generic Iterator
- Loop a list with using ListIterator
- Loop through a ist in reverse direction using ListIterator
- Remove an element by value and by index from List
- Remove all elements from a List
- Remove duplicate items from a List
- Remove item from a List while looping
- Remove range of elements from a List
- Remove user object from a list
- Replace an Element of List
- Replace all occurrences of specified element in a List
- Replace an element in a List using ListIterator
- Reverse a List
- Reverse order of all elements in a List
- Rotate elements of a list
- Search a List for an item with contains method
- Search elements of a List
- Binary Search a Sorted List
- Binary Search for a non-existent element in a List
- Set to change(replace) the value in a list
- Shuffle elements in a List
- Shuffle(repeatable) a List
- Sort a list
- Sort a List in descending order using comparator
- Swap elements of List