数组分割


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
 * Created by Administrator on 2019-6-22 0022.
 */
public class GroupUtils {

    /**
     * 按照多少页分成多少组
     * @param list
     * @param peer
     * @param shuffle
     * @return
     */
    public static List groupArray(List list, int peer, boolean shuffle){
        if(shuffle==true){
            Collections.shuffle(list);
        }
        if(peer==0){
            peer=1;
        }
        Double per= new Double(peer);
        int c = new Double(Math.floor(list.size()/per)).intValue();
        List newList= new ArrayList<>();
        if(c==0){
            newList.add(list);
            return newList;
        }
        for(int i=0;i groupArrayByCount(List list, int peerCount, boolean shuffle){
        List newList= new ArrayList<>();
        if(shuffle==true){
            Collections.shuffle(list);
        }
        if(list.size()<=peerCount){
            newList.add(list);
            return newList;
        }
        int page= (int) Math.ceil(list.size()/new Double(peerCount));
        for(int i=0;ilist.size()){
                newList.add(list.subList(from,list.size()));
            }else {
                newList.add(list.subList(from,peerCount+from));
            }

        }
        return newList;
    }

//    public static void main(String[] args) {
//        List lists= new ArrayList<>();
//        List strings= new ArrayList<>();
//        for (int i = 0; i <1000 ; i++) {
//            strings.add(i);
//        }
//        lists= groupArrayByCount(strings,333,false);
//        System.out.print(lists);
//    }
}

你可能感兴趣的:(数组分割)