public static String removeWhiteSpaces(String str){String s = "";char[] arr = str.toCharArray();for (int i = 0; i < arr.length; i++) {int temp = arr[i];if(temp != 32 && temp != 9) { // 32 ASCII for space and 9 is for Tabs += arr[i];}}return s;}
public Address(String street, String city, String state, String zip ) {this.street = street;this.city = city;// Now checking to make sure that state has no spaces...int position = state.indexOf(" ");if(position >=0) {//now putting state back together if it has spaces...state = state.substring(0, position) + state.substring(position + 1);}}
public static void main(String[] args) {String withSpace = "Remove white space from line";StringBuilder removeSpace = new StringBuilder();
for (int i = 0; i<withSpace.length();i++){if(!Character.isWhitespace(withSpace.charAt(i))){removeSpace=removeSpace.append(withSpace.charAt(i));}}System.out.println(removeSpace);}
public String removeSpace(String str) {String result = "";for (int i = 0; i < str.length(); i++){char c = str.charAt(i);if(c!=' ') {result += c;}}return result;}