arrays - How to break an Integer[] arr in more than one interger[] arrs in Java? -


i have comma separated string of ids. want break comma separated string in more 1 strings if total no. of ids greater 500.

what can do: can convert string in integer array , test it's size. break array in more 1 arrays, , re-convert them in comma separated strings.

my code far:

 integer[] empidint = null;      string tokens[]=application.splitstr(outerarray, ",");                       if(!ermutil.isnull(tokens) && tokens.length>0){                                  empidint=new integer[tokens.length];                           for(int i=0;i<tokens.length;i++){                               empidint[i]=integer.valueof(tokens[i]);                           }                        } 

questions

  1. is right approach tackle problem?
  2. if yes,how break integer[] array in more 1 arrays?
  3. if no, should do?

edit: input : "1,2,3,4,5,6,7,8,9,10,11" //list of ids;

i want break them more 1 string if no. of ids greater let's 3. it's 10 i.e total no. of ids. output might

output "1,2,3" //1st string
"4,5,6" //2nd string
"7,8,9" //3rd string
"10" //4th string

i have use list<string> store data , per count have use list.sublist(fromindex,toindex) method sublist main list.

try below code :

        string str = "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15";         string[] ar_str = str.split(",");         list<string> list = arrays.aslist(ar_str);          int count = 4;         int fromindex = 0;         int toindex = count;         for(int i=0;i<list.size()/count;i++){             fromindex = * count;             toindex = fromindex + count;             list<string> temp = list.sublist(fromindex, toindex);             system.out.println(temp); //convert list comma separated string         }         if(list.size()%count > 0){             system.out.println(list.sublist(toindex, list.size()));         } 

output

[1, 2, 3, 4] [5, 6, 7, 8] [9, 10, 11, 12] [13, 14, 15] 

may you.


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -