java Map

/**

     * Realize that there are hundreds of thousands of pieces of data in the list collection in java, and every 100 pieces are taken out as a group

     * @param list can penetrate a list of hundreds of thousands of data

     * @return map List of 100 pieces of data in each Kye

     */

    @SuppressWarnings({ "unchecked", "rawtypes" })

    public Map groupList(List list){

        

        int listSize=list.size();

        int toIndex=100;

        Map map = new HashMap(); //Use map to store new grouped data

        int keyToken = 0;

        for(int i = 0;i<list.size();i+=100){

            if(i+100>listSize){ //The function is that if there are no 100 pieces of data at the end of toIndex, just install a few pieces in the remaining newList

                toIndex=listSize-i;

            }

        List newList = list.subList(i,i+toIndex);

        map.put("keyName"+keyToken, newList);

        keyToken ++;

        }

        

        return map;

    }

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326307307&siteId=291194637