这不是我的问题的重复.我检查它和我是如何利用适当的谓词和 THAT约为removeIf和删除之间的差异.
我是Java初学者.
昨天,我试着按照这个教程https://dzone.com/articles/why-we-need-lambda-expressions
在我学会了如何使用Lambda表达式和谓词后,我自己制作了代码来练习.
比如,总和所有数字if(n%3 == 0 || n%5 == 0).这是我的代码.
public class Euler1Lambda {
long max;
public Euler1Lambda(long max) {
this.max = max;
}
public static boolean div3remainder0(int number) {
return number % 3 == 0;
}
public static boolean div5remainder0(int number) {
return number % 5 == 0;
}
public long sumAll() {
long sum = 0;
for(int i=1; i<max; i++) {
if (div3remainder0(i) ||div5remainder0(i)) {
sum += i;
}
}
return …Run Code Online (Sandbox Code Playgroud) 我是Java初学者.
今天,我练习了如何在java中复制文件并尝试按照本教程
http://www.journaldev.com/861/4-ways-to-copy-file-in-java
完成本教程后,我运行了JMH使用57MB txt文件检查性能的基准测试.
nioFiles和NIOChannel之间存在性能差距,比我预期的要大.
Benchmark Mode Cnt Score Error Units
CompressTest.fileCopyUsingNIOChannelClass thrpt 10 22.465 ± 2.996 ops/s
CompressTest.fileCopyWithNIOFiles thrpt 10 0.843 ± 0.488 ops/s
Run Code Online (Sandbox Code Playgroud)
这是我用过的代码
@Warmup(iterations = 5, time = 1000, timeUnit = TimeUnit.MILLISECONDS)
@Measurement(iterations = 10, time = 1000, timeUnit = TimeUnit.MILLISECONDS)
@Fork(1)
@State(Scope.Benchmark)
public class CompressTest
{
final static Path source = Paths.get("c:/temp/system.out.lambda.txt");
final static Path target = Paths.get("c:/temp/copied.lambda.txt");
public static void main(String[] args) throws RunnerException, IOException {
Main.main(args);
}
@Benchmark
public static void fileCopyWithNIOFiles() throws …Run Code Online (Sandbox Code Playgroud)