shuffle 메소드
- Colletions에 있는 메소드 중 shuffle() 메소드는 배열이나 리스트를 랜덤으로 출력할 때 사용
public class ShuffleEx {
public static void main(String[] args) {
ArrayList<String> fruitList = new ArrayList<>();
fruitList.add("apple");
fruitList.add("banana");
fruitList.add("grape");
fruitList.add("melon");
fruitList.add("orange");
System.out.println("fruitList = " + fruitList);
Collections.shuffle(fruitList);
System.out.println("shuffleFruitList = " + fruitList);
}
}
fruitlist = [apple, banana, grape, melon, orange]
shuffleFruitList = [melon, banana, orange, grape, apple]