- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRemoveWhiteSpacesExample.java
More file actions
Latest commit
28 lines (24 loc) · 834 Bytes
/
Copy pathRemoveWhiteSpacesExample.java
File metadata and controls
28 lines (24 loc) · 834 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
packagecom.codinginterview;
importjava.util.Arrays;
publicclassRemoveWhiteSpacesExample {
publicstaticvoidmain(String[] args) {
System.out.println("Remove White Spaces from the String Example!");
StringinputString = " Hello Ram ";
StringBuildersb = newStringBuilder();
char[] charArray = inputString.toCharArray();
for(charc : charArray){
if(!Character.isWhitespace(c)){
sb.append(c);
}
}
System.out.println(sb.toString());
// Leading and Trailing spaces
Stringstr = " abc def\t";
str = str.strip();
System.out.println(str);
// Sort an Array
int[] numbers = {2,1,44,20,4,66,4};
Arrays.sort(numbers);
System.out.println(Arrays.toString(numbers));
}
}