BASE-4618: Create new module, local variable example

This commit is contained in:
Daniel Strmecki
2021-02-14 12:12:48 +01:00
parent 56e2e3ca09
commit f55e2ea15b
4 changed files with 91 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
package com.baeldung.finalkeyword;
public class LocalVariableFinal {
public static void main(String[] args) {
for (int i = 0; i < 1500; i++) {
long startTime = System.nanoTime();
String result = concatStrings();
long totalTime = System.nanoTime() - startTime;
if (i >= 500) {
System.out.println(totalTime);
}
}
}
private static String concatStrings() {
final String x = "x";
final String y = "y";
return x + y;
}
}

View File

@@ -0,0 +1,22 @@
package com.baeldung.finalkeyword;
public class LocalVariableNonFinal {
public static void main(String[] args) {
for (int i = 0; i < 1500; i++) {
long startTime = System.nanoTime();
String result = concatStrings();
long totalTime = System.nanoTime() - startTime;
if (i >= 500) {
System.out.println(totalTime);
}
}
}
private static String concatStrings() {
String x = "x";
String y = "y";
return x + y;
}
}