java打乱ArrayList随机

public static  boolean isEmpty(ArrayList sourceList) {
        return (sourceList == null || sourceList.size() == 0);
    }

/**
     * 打乱ArrayList
     * 
     * */
    public static  ArrayList randomList(ArrayList sourceList){
    	if (isEmpty(sourceList)) {
            return sourceList;
        }
    	
    	ArrayList randomList = new ArrayList( sourceList.size( ) );
    	do{
    		int randomIndex = Math.abs( new Random( ).nextInt( sourceList.size() ) );
        	randomList.add( sourceList.remove( randomIndex ) );
    	}while( sourceList.size( ) > 0 );
    	
    	return randomList;
    }

``


你可能感兴趣的:(java)