Java string splitting and string joins

Source: Internet
Author: User

There seems to be no function in Java for splitting and connecting strings, I wrote a

1  Public classlierstring{2 //------------------------------------------------------------------------3 //accepts a string containing a space and returns an array of strings4  Public Staticstring[] Tosarr (String Arg) {5 //System.out.println ("Enter function STRTOASRR");6arg+= "";7 Char[] p=Arg.tochararray ();8String[] Strs=NewString[50];9 Ten intStri=0; One intJ=-1; A      for(inti=0;i<p.length;) { -         if(p[i]== "){ -             if(i-j>1){                 theStrs[stri]=arg.substring (j+1, i); -stri++; -j=i; -                 //System.out.println (strs[stri-1]); +                 } -             Else  +j=i; A             } ati++; -  -         } -String[] Atrs=NewString[stri]; -  for(inti=0;i<stri;i++){ -  inatrs[i]=Strs[i]; -     } to //System.out.println (stri); + returnATRs; -  the } * //------------------------------------------------------------------------ $ //takes an array of strings, returns a string, joins all the strings in the string array, splits them with spacesPanax Notoginseng  Public StaticString Linkarr (string[] x,intIintj) { - if(i>j) the return NULL; + if(j>=x.length) A return NULL; theString a= ""; +StringBuffer SB =NewStringBuffer (); -  for(intp=i;p<=j;p++){ $ sb.append (x[p]); $ Sb.append (a); - } - returnsb.tostring (); the } -  Public StaticString Linkarr (string[] x,inti) {Wuyi returnLinkarr (x,i,x.length-1); the } -  Public StaticString Linkarr (string[] x) { Wu returnLinkarr (x,0); - } About}

Java string splitting and string joins

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.