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)