最代码官方
								2016-09-20 13:49:05
							
							
								原证
							java ArrayList集合数据进行分页的代码片段
平常工作中,有些业务查询规则较为复杂,所以经常会把数据库中的数据一次性加载到java内存中,然后在ArrayList中进行分页查询,分享下相关代码片段
public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        list.add(5);
        int page = 2;
        int count = 3;
        int size = list.size();
        int fromIndex = count * (page - 1);
        int toIndex = fromIndex + count;
        if (toIndex >= size) {
            toIndex = size;
        }
        System.out.println(list.subList(fromIndex, toIndex));
    }
运行结果如下:
代码虽然简单,但在开发中确实经常用到,总结分享到最代码以便需要的时候用,确实是个很好的习惯。
猜你喜欢
请下载代码后再发表评论
     相关代码
相关代码
				 最近下载
最近下载
				 最近浏览
最近浏览
				
                斧头帮副帮主     LV5
                2023年4月2日
            
            
        
                微信网友_6040315240812544     LV8
                2022年10月20日
            
            
        
                小白小怪     LV10
                2022年9月18日
            
            
        
                981352576     LV4
                2022年5月11日
            
            
        
                等你归来     LV2
                2022年3月6日
            
            
        
                gentleman1576     LV2
                2021年12月4日
            
            
        
                小白jmhuang     LV12
                2021年5月28日
            
            
        
                小星七的     LV12
                2021年3月16日
            
            
        
                猫喵喵的名字     LV6
                2021年1月28日
            
            
        
                Diontll     LV3
                2020年11月23日
            
            
        




 
                 
    