On-Machine Topic (intermediate)-Re-split the string in the array by the specified length (Java)

Source: Internet
Author: User

The topics are as follows:


The code is as follows:

Package Huawei;import Java.util.arraylist;public Final class demo{/* * function: Write a function, enter as an array of strings, * Iinputlenth each string in the split fraction group by the specified length to output to the new string array. Strings that are not iinputlenth integer multiples are appended with the number 0. * Empty string is not processed, an empty string is encountered to indicate the end of the array, and the function returns.  Input: String inputstrarray array pointer * Maximum string number is 50, string length max 255 int iinputlenth specified split length iinputlenth>=1 && <=32 * Return: string array pointer * * Example split input by length 8: ABC 12345789 return: abc00000 12345678 90000000 */public static string[] Convertstringarray (Str Ing[] Inputstrarray, int iinputlenth) {if (iinputlenth >= 1 && iinputlenth <= 32)//split length {arraylist<string > arrayList = new arraylist<string> (); for (int i = 0; i < inputstrarray.length; i++) {String srcstring = InputS Trarray[i];if (srcstring.length () > 0)//NOT NULL {char src[] = Srcstring.tochararray ();//convert string to character array int len = src.length;// Character array length StringBuilder SB = new StringBuilder (); Boolean iscontinue = True;int ring = 1;//is used to empty the count for (int index = 0; iscontinue ; index++, ring++) {if (index = = (len-1))//length and index at the same time {sb.append (Src[index]int tmp_len = Sb.length (); for (; Tmp_len < iinputlenth; tmp_len++) {Sb.append ("0");//Complement 0}arraylist.add (sb.tostring ( )); iscontinue = false;//no longer continues} else{sb.append (Src[index]);//The character array turns into if (ring = = Iinputlenth)//If the length equals the split length, a split is made, Put SB into list and empty SB, next round start {ring = 0;arraylist.add (sb.tostring ()); sb = new StringBuilder ();}}}} if (arraylist.size () > 0) {String data[]=new string[arraylist.size ()];d ata=arraylist.toarray (data);// Turn list to string array return data;}} return null;}}


On-Machine Topic (intermediate)-Re-split the string in the array by the specified length (Java)

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.