去空格

 1 public class zuoye3 {
 2 
 3     public static void main(String[] args) {
 4         // TODO 自动生成的方法存根
 5 
 6         String str2="zhnag we i";
 7         System.out.println("去空格为");
 8         for (int i=0;i<str2.length();i++)
 9         {
10             String str3=str2.substring(i, i+1);
11             
12             if(str3.equals(" "))
13             {
14                 
15             }
16             
17             else{
18                 System.out.print(str3);
19             }
20     
21         }System.out.println();
22         
23         
24         
25         
26         
27     }
28 
29 }
String m=" j a v a ";
        
        String n= m.replace(" ", "");
        
        System.out.println("去掉空格后为"+n);

原文地址:https://www.cnblogs.com/crazy-zw/p/5128731.html