最近做一个服务器项目,别人的接口有数据长度限制,于是有这么一个DEMO
import java.util.ArrayList; import java.util.List; public class TestListOutput { public static void main(String[] args) { //init List<Long> productIds = new ArrayList<Long>(); for(int i=1;i<=523;i++) { productIds.add(new Long(i)); } int size = productIds.size(); System.out.println(size); List<Long> childlist = new ArrayList<Long>(); for(Long productId:productIds){ childlist.add(productId); if(childlist.size()==50){ for(int i=0;i<childlist.size();i++) { System.out.print(childlist.get(i)+" "); } System.out.println("----"); childlist.clear(); } } if(childlist.size()>0){ System.out.println("----"); for(int i=0;i<childlist.size();i++) { System.out.print(childlist.get(i)+" "); } } } }