自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(10)
  • 收藏
  • 关注

原创 Exception和RuntimeException

Exception是检查型异常,在程序中必须使用try...catch进行处理;RuntimeException是非检查型异常,例如NumberFormatException,可以不使用try...catch进行处理,但是如果产生异常,则异常将由JVM进行处理;public class Exception01 { public static void testRuntimeException() throws RuntimeException{ throw new RuntimeEx

2021-10-08 11:55:05 208

原创 BiFunction介绍

BiFunction接受两个任意类型参数并返回一个任意类型对象@FunctionalInterfacepublic interface BiFunction<T, U, R> { R apply(T t, U u);}BiFunction 与Function连用private void bifunction() { BiFunction<Integer,Integer,Double> biFunction = (a,b)->Math.po

2021-10-07 17:12:12 7248

原创 BinaryOperator介绍

BIFunction是接收2个任意类型的参数,返回值也是任意类型@FunctionalInterfacepublic interface BiFunction<T, U, R> { R apply(T t, U u);}BinaryOperator是接收2个相同类型的参数,返回值也是同一种类型@FunctionalInterfacepublic interface BinaryOperator<T> extends BiFunction<T

2021-10-07 12:33:14 654

原创 Optional和stream的使用

原来的Null值判断String s = test();if (null != s) { System.out.println(s);}使用OptionalNull判断Optional<String> s = Optional.ofNullable(test());s.ifPresent(System.out::println);

2021-10-06 17:21:57 496

原创 java8 lambda表达式、函数式接口

lambda表达式 实现了具有单一方法的接口,如:new Thread( () -> System.out.println("Hello world!"););Runnable接口只有一个run方法,就是具有单一方法的接口,可以用lambda表达。

2021-10-05 17:07:26 101

原创 Comparable与Comparator的区别

Comparable & Comparator都是用来实现集合中元素的比较、排序的,只是 Comparable 是在集合内部定义的方法实现的排序,Comparator 是在集合外部实现的排序,所以,如想实现排序,就需要在集合外定义Comparator接口的方法或在集合内实现 Comparable接口的方法,Comparator位于包java.util下,而Comparable位于包java.lang下。Java中有两种方式来提供比较功能。第一种是实现java.lang.Comparable接口,

2021-10-03 10:27:26 83

原创 CompletableFuture 并行及串行

public class Main { public static void main(String[] args) throws Exception { // 两个CompletableFuture执行异步查询: CompletableFuture<String> cfQueryFromSina = CompletableFuture.supplyAsync(() -> { return queryCode("中国石油"...

2020-11-29 15:36:28 336

原创 多个CompletableFuture 串行执行

多个CompletableFuture可以串行执行public class Main { public static void main(String[] args) throws Exception { // 第一个任务: CompletableFuture<String> cfQuery = CompletableFuture.supplyAsync(() -> { return queryCode("中国石油");...

2020-11-29 09:58:40 1489

原创 CompletableFuture1

创建一个CompletableFuture是通过CompletableFuture.supplyAsync()实现的,它需要一个实现了Supplier接口的对象CompletableFuture已经被提交给默认的线程池执行了,我们需要定义的是CompletableFuture完成时和异常时需要回调的实例。完成时,CompletableFuture会调用Consumer对象:public interface Consumer<T> { void accept(T t);}

2020-11-29 09:55:59 64

原创 Future异步

import java.util.concurrent.Callable;import java.util.concurrent.ExecutionException;import java.util.concurrent.ExecutorService;import java.util.concurrent.Executors;import java.util.concurrent.Future;public class CalBFutrueTest { public static .

2020-11-29 08:44:52 40

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除