java Map

/**

     * 实现java 中 list集合中有几十万条数据,每100条为一组取出

     * @param list 可穿入几十万条数据的List

     * @return map 每一Kye中有100条数据的List

     */

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

    public Map groupList(List list){

        

        int listSize=list.size();

        int toIndex=100;

        Map map = new HashMap();     //用map存起来新的分组后数据

        int keyToken = 0;

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

            if(i+100>listSize){        //作用为toIndex最后没有100条数据则剩余几条newList中就装几条

                toIndex=listSize-i;

            }

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

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

        keyToken++;

        }

        

        return map;

    }

猜你喜欢

转载自kfcman.iteye.com/blog/2410363