Shuffle List ArrayList Collections Java example

Add and shuffle elements in LinkedList or ArrayList Java basic example.

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
 
public class MainClass {
	public static void main(String[] arg) {
		String[] arrayOfString = {"nothing", "Hello", "people"
				, "bye-bye", "hello", "world!", "End" };
		   List<String> arrayList = new LinkedList<String>();
            for(String s: arrayOfString)
		     arrayList.add(s);
 
		    Collections.shuffle(arrayList);
 
		    System.out.println(arrayList);
 
		  }
}
/*
[hello, world!, bye-bye, nothing, people, End, Hello]
*/
This entry was posted in Android Examples Code, Array,List,Collections and tagged , , , , , . Bookmark the permalink.


Comments are closed.



7,071 views