1 public void getRandom() { 2 List<Integer> list = new ArrayList<Integer>(); 3 for (Integer integer : i) { 4 list.add(integer); 5 } 6 Random random = new Random(); 7 while (true) { 8 int index = random.nextInt(list.size()); 9 System.out.println(list.get(index)); 10 list.remove(index); 11 if (list.isEmpty()) { 12 break; 13 } 14 } 15 }
public static void getRandom() { List<String> list = new ArrayList<String>(Arrays.asList("red", "orage", "yellow", "green", "blue", "pink")); System.out.println("Beffore Shuffle : " + list); Collections.shuffle(list); System.out.println("After Shuffle : " + list); }