remove extra blank spaces from string in java

Solutions on MaxInterview for remove extra blank spaces from string in java by the best coders in the world

showing results for - "remove extra blank spaces from string in java"
Maelly
16 Nov 2018
1import java.util.Scanner;
2class RemoveExtraSpace{ //starting of class
3    public static void main(String[] args){ //starting of the main function
4        Scanner sc=new Scanner(System.in); //declaring an object of the Scanner class
5        String input,output=""; 
6        char c;
7        int i,len;
8        System.out.println("ENTER A SENTENCE.");
9        input=sc.nextLine().trim(); //accepting the input
10        len=input.length();
11        for(i=0;i<len;i++){ //outer for loop to traverse each character
12            c=input.charAt(i);
13            output+=c;
14            if(c==' '){
15                while(input.charAt(i)==' '){ //inner while loop to skip through repeated spaces
16                    i++;
17                } //end of while loop
18                i--; //decrementing i by 1 so that the immediate character after space is taken
19            }
20        } //end of for loop
21        System.out.println(output); //printing the result
22    } //closing of main function
23} //closing of class
queries leading to this page
how to remove extra spaces and non character in java remove extra space from a stringremove extra spaces in string javaremove all spaces in string javaremove unnecessary spaces in data javajava how to remove whitespace from a stringjava remove spaces from stringhow to remove empty spaces from a string in java with regexjava string remove word including space if it has a spaceremove empty spaces from javaeliminate all spaces from string javahow to remove extra whitespace from a string but keep just one in javahow to remove extra spaces in string javaremove spaces in a string javahow to remove space before and after a string in javahow to remove middle extra spaces in string javajava remove whitespace from stringhow to remove space in string in javahow to remove spaces in java stringjava remove all spaces from stringstring remove spaces javaremove extra spaces between words in javahow to remove spaces in a string in javahow to trim extra spaces in javaremove spaces from string javahow to remove spaces from end of string in javaremove additional spaces in java stringremove extra spaces from string in javajava remove any whitespace from stringjava code to remove extra whitespace in a stringremove space fron string javajava remove spaces from a stringremoving white spaces from the begining of string in javahow to remove extra spaces in javahow to remove extra space at the end of a string in java using string functionshow to remove spaces from string in javaremove extra spacesremove extra whitespaces from string in javastring remove extra spacescan not exclude blank spaces in javahow to remove extra space in java using string functionsstring remove space javajava remove spaces from string functionjava string remove all empty spaces in stringjava how to get rid of empty spacesjava trim extra spacesremove whitespace in string in javaremove extra spaces from end of the word javaremove spaces in javahow to remove all spaces in a string java 27java remove spacesfunction to remove spaces from string in javaremove trailing spaces in java stringremove extra spaces from string javaremove double spaces in string javaremove space in a string in javahow to remove the space in a string javahow to remove spaces in string javaremove empty space from stringremove extra whitespace in java in a fileremove space in a string javaremove spaces in java 5cjava remove spaces if they 27re not in between two stringsremove extra spaces around and in the string in java 8java remove spaces if they 27re not in between a stringremove space string javahow to remove spaces form word java splitremove spaces at the end of string javaremove space in string javahow to remove space string before and after in javahow to remove spaces from a string javahow to remove all spaces from a string in javajava remove spaces in stringjava regex to remove extra spaceremoving trailing spaces in javaremove extra whitespace in javaremove extra spaces from name javahow to remove spaces in between string in javajava how to remove spaces from a stringjava remove extra space from stringdelete all spaces in java stringremove spaces in string of javaremove all spaces from string in javahow to remove middle extra spaces in string java gfgtrim extra spaces in javaremove all spaces from string javahow to remove all spaces in string in javahow to remove extra white space in word in javajava remove space from stringhow to remove empty spaces in word with javaremove extra spaces from a stringjava remove whitespace from end of stringhow to remove all spaces in string javaremove whitespace from string javahow to remove all spaces from string in javaremove extra spaces from end of the word string javaremove whitespace from string in javahow to remove empty space in string in javahow to remove spaces in string in javahow to delete an extra space in javahow to remove extra space from stringhow to remove extra space from string in javaremove extra spaces around and int the stringjava delete spaces in stringjava remove extra spacesremove whitespace in string javajava regex remove extra spacesremove spaces in between string javajava remove spaces stringremove space in java stringremove all spaces string javaremove extra spaces between words in string javajava remove certain whitespaceremove tabulation of space from string javajava remove whitespace in stringremove extra space in a sentence javaremove all spaces from a string javajava remove empty spaces from stringremove the space in a string in javajava string remove al spaceshow to remove spaces in strings in javastring remove empty spaces javaremove tabulation or space from string javaremove extra spaces from string in javaremove blank spaces in word using javajava remove double spaces from stringjava string remove spaceshow to remove extra spaces in a stringhow to remove extra spaces stringhow to remove blank spaces in a string javaremove extra spaces around the stringremove all blank spaces in string javaeliminate spaces from a string in javahow to remove a space in a string javaremove extra blank spaces from string in java