BASE-4618: Create new module, local variable example
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user