Method of removing the hollow lattice of a string (2016.1.12p141-2)

Source: Internet
Author: User

1 //Forif to handle spaces2         //Method One3String str = "WW SSE RR";4 5String str1;//define an intermediate variable6 7String str2 = "";//define an intermediate variable8 9          for(inti = 0; I < str.length (); i++) {Ten  OneSTR1 = str.substring (i, i + 1); A  -             if(! (Str1.indexof ("") >= 0)) { -  theSTR2 = str2 +str1; -             } -         } -System.out.println ("string with whitespace removed" +str2); +  -         //method two using split split +String STR5 = "ww SSE RR"; A  atSystem.out.print ("string with whitespace removed"); -  -string[] STR6 = Str5.split (""); -  -          for(String x:str6) { -  in             if(!x.equals ("")) { -  to System.out.print (x); +             } -         } the System.out.println (); *  $         //Replace replaces find to handle spacesPanax Notoginseng         //Method Three -String STR3 = "ww SSE RR"; the  +String STR4 = Str3.replace ("", ""); A  theSystem.out.println ("string with whitespace removed" + STR4);

Results of the operation:

Method of removing the hollow lattice of a string (2016.1.12p141-2)

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.