Wednesday, 16 March 2016

Remove white space from String

package com.tutorial4u;

import java.util.Scanner;

public class RemoveWwhiteSpace {
       public static void main(String[] args) {
             System.out.println("Enter any string : ");
             Scanner sc = new Scanner(System.in);
             String str = sc.nextLine();
             char[] c = str.toCharArray();
             StringBuffer sb = new StringBuffer();
             for(int i=0; i<c.length; i++){
                    if((c[i] !=' ')&& (c[i] !='\t')){
                           sb.append(c[i]);
                    }
             }
             System.out.println(sb);
       }


}

Output:

Enter any string :
Welcome To Tutorial4u
WelcomeToTutorial4u

No comments:

Post a Comment

No of Occurrence in Array

package com.tutorial4u; import java.util.HashMap; /************************************************************  No of Occurrence in Array...