Drop Down

Wednesday, February 6, 2019

RemoveWhiteSpace_PrintNoLasComma

public class RemoveWhiteSpace_PrintNoLasComma{

public static void main(String[] args)
{
   String str = "Hello wor   ld";
   str = str.replaceAll("\\s","");
   //System.out.println(str);
   char[] ch = str.toCharArray();
   for(int i =0;i<ch.length;i++)
   { 
   System.out.print((i == 0 ? ch[i] :","+ch[i] ));
   }

}

}

No comments:

Post a Comment

Java 8 Notes Pics