1. 程式人生 > >list亂序輸出

list亂序輸出

	public static <V> List<V> randomList(List<V> sourceList) {
		if (sourceList == null || sourceList.size() == 0) {
			return sourceList;
		}
		List<V> random = new ArrayList<V>(sourceList.size());
		do {
			int index = Math.abs(new Random().nextInt(sourceList.size()));
			random.add(sourceList.remove(index));

		} while (sourceList.size() > 0);

		return random;

	}