package text.work;
import java.util.ArrayList;
import java.util.List;
public class Text {
private static List idList = new ArrayList();
private static List resultList = new ArrayList();
/**
* 将List中的数据组成用逗号分隔的字符串,如'a','b','c'
* @param strList
* @return
*/
public static String getStr(List<String> strList) {
String resultStr = "";
if (strList != null && strList.size() > 0) {
for (int i = 0; i < strList.size(); i++) {
resultStr = resultStr + "'" + strList.get(i) + "'" + ',' ;
}
resultStr = resultStr.substring(0, resultStr.length() - 1);
}
return resultStr;
}
/**
* 传入数组大于设定条数,则按设定的条数进行分解
* eg:数组:'a','b','c','d','e','f','g'
* 传入设定值为2
* 则返回: resultList.get(0) = 'a','b'
* resultList.get(1) = 'c','d'
* resultList.get(2) = 'e','f'
* resultList.get(3) = 'g'
* @param list
* @param updateCount
* @return resultList
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public static List resultList(List<String> list,int updateCount){
List l = new ArrayList();
if(list.size() > updateCount){
for(int i = 0;i < updateCount;i ++){
l.add(list.get(0));
list.remove(0);
}
resultList.add(getStr(l));
if(list.size() > updateCount){
resultList(list,updateCount);
}else{
resultList.add(getStr(list));
}
}else{
resultList.add(getStr(list));
}
return resultList;
}
/**
* @param args
*/
@SuppressWarnings("unchecked")
public static void main(String[] args) {
Text();
List resultList = resultList(idList,10);
System.out.println(resultList);
System.out.println(resultList.size());
for(int i = 0;i < resultList.size();i++){
System.out.println(resultList.get(i));
}
}
@SuppressWarnings("unchecked")
private static void Text() {
for(int i = 0;i < 76;i++){
idList.add(i+"");
}
}
}
测试结果如下