- package com.tw.str.util;
- import java.util.ArrayList;
- import java.util.Iterator;
- import java.util.List;
- /**
- *<p>拆分字符串为n节字符</p>
- * @author tangw 2010-12-27
- *
- */
- public class StrTest {
- /**
- * @param args
- */
- public static void main(String[] args) {
- //
- List list =test("1234567890123456789");
- for(int i=0;i<list.size();i++){
- System.out.println(i+"=="+list.get(i));
- }
- }
- public static List test(String str){
- if(str==null)return null;
- List list = new ArrayList();
- int len = str.length();
- int currIndex = 2;//1024*100;
- if( len > currIndex ){
- int endIndex = 0;
- int begIndex = 0;
- String p_str = null;
- while( endIndex<len ){
- endIndex = endIndex+currIndex;
- if( endIndex <len ){
- p_str = str.substring(begIndex,endIndex);
- list.add(p_str );
- begIndex = endIndex;
- }else{
- p_str = str.substring(begIndex);
- list.add(p_str );
- }
- }
- }else{
- list.add(str);
- }
- return list;
- }
- }
转载于:https://blog.51cto.com/wen5566/464553