This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.function.IntFunction; | |
import java.util.stream.IntStream; | |
public class FizzBuzz { | |
static <R> IntFunction<R> ifmod(int m, R r, IntFunction<R> f) { | |
return (int i) -> (i % m == 0) ? r : f.apply(i); | |
} | |
public static void main(String[] args) { | |
IntStream.rangeClosed(1, 100) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import java.util.function.*; | |
import java.util.stream.*; | |
import static java.util.stream.Collectors.*; | |
import static java.util.Comparator.*; | |
/** | |
* http://stackoverflow.com/questions/22845574/how-to-dynamically-do-filtering-in-java-8 | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.kenfogel.performance.loaders; | |
import java.util.*; | |
import java.util.concurrent.TimeUnit; | |
import org.openjdk.jmh.annotations.*; | |
/** | |
* Performs a set of tests to determine the Big-O performance of an array list, array deque, | |
* and linked list. | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat Printf.java | |
public class Printf { | |
public static void main(String[] args) { | |
System.out.println("Locale.getDefault()=" + java.util.Locale.getDefault()); | |
System.out.printf("%.3f%n", 123.45); | |
} | |
} | |
$ javac Printf.java | |
$ java -version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
import java.util.Collection; | |
import java.util.List; | |
import java.util.Optional; | |
import java.util.function.Consumer; | |
import java.util.function.Function; | |
import java.util.stream.Stream; | |
// Suppose we have an API where: | |
// - a Clazz has a List of Methods, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package masterclass; | |
import java.util.*; | |
import java.util.stream.*; | |
import java.util.Map.Entry; | |
import static java.util.Map.entry; | |
import static java.util.stream.Collectors.*; | |
public class MasterClass { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.readFile.readFileJava; | |
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.nio.file.Files; | |
import java.nio.file.Path; | |
import java.time.Duration; | |
import java.time.Instant; | |
import java.util.ArrayList; | |
import java.util.Collections; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- ReadFileJavaApplicationBufferedReader1.java | |
+++ ReadFileJavaApplicationBufferedReader2.java | |
@@ -29,17 +29,12 @@ | |
// get total line count | |
Instant lineCountStart = Instant.now(); | |
- int lines = 0; | |
Instant namesStart = Instant.now(); | |
ArrayList<String> names = new ArrayList<>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- ReadFileJavaApplicationBufferedReader0.java | |
+++ ReadFileJavaApplicationBufferedReader1.java | |
@@ -57,8 +57,8 @@ | |
// System.out.println(readLine); | |
// get all the names | |
- String array1[] = readLine.split("\\s*\\|\\s*"); | |
- String name = array1[7]; | |
+ String array1[] = readLine.split("\\|", 9); | |
+ String name = array1[7].strip(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- ReadFileJavaApplicationBufferedReader2.java | |
+++ ReadFileJavaApplicationBufferedReader3.java | |
@@ -44,6 +45,7 @@ | |
Instant commonNameStart = Instant.now(); | |
ArrayList<String> firstNames = new ArrayList<>(); | |
+ var namePat = Pattern.compile(", \\s*(([^ ]*), |([^ ]+))"); | |
System.out.println("Reading file using " + Caller.getName()); | |
OlderNewer