将数组截取
来源:互联网 发布:汽车模型设计软件 编辑:程序博客网 时间:2024/04/30 03:27
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+"");
}
}
}
测试结果如下
- 将数组截取
- 将字符串截取到二维数组中
- php 将中文字符串截取为数组
- 数组 截取
- 用js语法处理将一个大数组截取成几个小数组的合集
- sql截取字符串数组
- c#截取数组
- php array_slice 截取数组
- JS -- 截取数组
- 截取数组元素slice
- C# 字节数组截取
- js截取数组
- jQuery 字符串截取与数组截取
- 将字符串截取成几条字符串
- Matlab将视频分段截取
- 写一个方法,将一个长度超过10的数组最后5项直接截取,不改变顺序变为前五项
- PHP 数组截取 array_slice() 函数
- java byte数组如何截取
- 如何编写高质量的缺陷报告
- Box2d源码学习<四>数学库API的实现
- 指针数组和数组指针的区别
- ubuntu下编译安装Fcitx 4.2.2, 配置Google输入法及云输入法
- git remote 简单用法 http://blog.csdn.net/xiruanliuwei/article/details/6919416
- 将数组截取
- js判断浏览器类型(IE,Firefox)
- std::hash_multimap 遍历同一key下的不同value
- 手把手教你如何优化C语言程序
- hdu 2053
- Box2d源码学习<五>b2Timer、b2Draw和b2Settings的实现
- html 模版
- 虚函数的性质
- gcc与makefile使用的常见问题和入门实例/GCC使用详解