Java Splits a String array into several small String arrays according to the same length.

Source: Internet
Author: User

Java Splits a String array into several small String arrays according to the same length.

Just call a method directly.

Private static Object [] splitAry (String [] ary, int subSize ){
// Divide by the length of the array by the number of content of each data, that is, the quotient is the number of arrays, and the Division is the quotient + 1 int count = ary. length % subSize = 0? Ary. length/subSize: ary. length/subSize + 1; // create a list where the object is list. Divide the original large array into small ones and add it to the list. List <String> subAryList = new ArrayList <List <String> (); // loop for (int I = 0; I <count; I ++ ){
// Locate the maximum subscript of each loop int index = I * subSize; List <String> list = new ArrayList <String> (); int j = 0;
// J is smaller than the maximum subscript of this group and smaller than the length of the entire large array. Add the qualified element to the list. while (j <subSize & index <ary. length) {list. add (ary [index ++]); j ++ ;}
// Then add the list to the large list, subAryList. add (list);} // create an Object array Object [] subAry = new Object [subAryList. size ()]; // looping through the large List for (int I = 0; I <subAryList. size (); I ++) {List <String> subList = subAryList. get (I); String [] subAryItem = new String [subList. size ()];
// Add the value traversal in the small list to the small array for (int j = 0; j <subList. size (); j ++) {subAryItem [j] = subList. get (j );}
Add a small array to subAry [I] = subAryItem;} return subAry ;}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.