数组分组代码模拟
2016-08-17 20:09
375 查看
<span style="font-size:14px;">/** * 数据分组 作用项目: 表情分组时数据拆分 * * @author syusikoku * @date 2016-8-17 */ public class DataSplitGroup2 { private static ArrayList<String> sourceList; /** * 1 -- 60 */ private static int allMaxDatas = 37; // 每组20条 private static int maxCount = 20; private static Map<Integer, List<String>> cacheGroupList; private static int startIndex; private static int endIndex; public static void main(String[] args) { sourceList = new ArrayList<String>(); initDatas(); splitDatas(); printMsg(); } private static void printMsg() { Set<Entry<Integer, List<String>>> entrySet = cacheGroupList.entrySet(); for (Entry<Integer, List<String>> entry : entrySet) { System.out.println( "pos:" + entry.getKey() + ",list:" + entry.getValue()); } } private static void splitDatas() { // TODO Auto-generated method stub // 每组20条 int latMaxSize = sourceList.size() / maxCount; cacheGroupList = new HashMap<Integer, List<String>>(); if (sourceList.size() % maxCount == 0) { for (int i = 0; i < latMaxSize; i++) { startIndex = i * maxCount; endIndex = (i * maxCount) + maxCount; cacheGroupList.put(i, sourceList.subList(startIndex, endIndex)); } } else { // 能够整除的数据 for (int i = 0; i < latMaxSize; i++) { startIndex = i * maxCount; endIndex = (i * maxCount) + maxCount; cacheGroupList.put(i, sourceList.subList(startIndex, endIndex)); } // 需要新增加一页 // 最后一页的数据 cacheGroupList.put(cacheGroupList.size(), sourceList.subList(endIndex, sourceList.size())); } } private static void initDatas() { for (int i = 0; i < allMaxDatas; i++) { sourceList.add("itcast :" + i); } } }</span>
相关文章推荐
- 有哪些编程必备的 Vim 配置?
- 让Java Thread线程暂停的三种方式
- C++的结构体与类的比较0817
- lesson6:java线程中断
- POJ 1469-COURSES(二分图匹配入门-匈牙利算法)
- 学习《spring 3.x企业应用开发实战》之使用Spring JDBC访问数据库
- Spring 框架简介
- Arrays类——Arrays.asList()方法使用
- 堆排序代码
- C语言字符输出格式化
- Qt 绑定本机的ip
- JAVA设计模式之--策略模式
- MATLAB和SIMULINK仿真 自动生成STM32工程
- JavaWeb学习篇之----Servlet过滤器Filter和监听器
- 使用jdk1.5的多线程 lock condition 实现方式实现 生产者消费者问题
- 数据的基本类型 java
- c/c++第十七天
- java访问权限,基本特征简述
- Git(三)-Github远程仓库
- 用Java实现电子邮箱email发送邮件