forked from PacktPublishing/Java-Coding-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
30 lines (21 loc) · 1.15 KB
/
Copy pathMain.java
File metadata and controls
30 lines (21 loc) · 1.15 KB
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
29
30
package modern.challenge;
import java.util.concurrent.TimeUnit;
public class Main {
private static final String TEXT = " My high\n\n school, the Illinois Mathematics and Science Academy, "
+ "showed me that anything is possible and that you're never too young to think big. \r"
+ "At 15, I worked as a computer programmer at the Fermi National Accelerator Laboratory, \t"
+ "or Fermilab. After graduating, I attended Stanford for a degree in economics and "
+ "computer science. ";
public static void main(String[] args) {
System.out.println("Input text: \n" + TEXT + "\n");
System.out.println("replaceAll() solution:");
long startTime = System.nanoTime();
String result = Strings.removeWhitespaces(TEXT);
displayExecutionTime(System.nanoTime() - startTime);
System.out.println("String without blanks is: \n" + result);
}
private static void displayExecutionTime(long time) {
System.out.println("Execution time: " + time + " ns" + " ("
+ TimeUnit.MILLISECONDS.convert(time, TimeUnit.NANOSECONDS) + " ms)");
}
}