DoubleSupplier:
代表一個double值結構的提供方
public static void main(String[] args) {
System.out.println("------DoubleSupplier------");
DoubleSupplier doubleSupplier=()->8.0;
double qe = 8.0;
double qt = 9.7;
DoubleSupplier doubleSupplier1=()->qe*qt;
System.out.println("DoubleSupplier>>>"+doubleSupplier.getAsDouble());
System.out.println("doubleSupplier1>>>"+doubleSupplier1.getAsDouble());
System.out.println("------DoubleSupplier------");
}
輸出內容爲:
------DoubleSupplier------
DoubleSupplier>>>8.0
doubleSupplier1>>>77.6
------DoubleSupplier------
DoubleToIntFunction:
接受一個double類型輸入,返回一個int類型結果。
public static void main(String[] args) {
System.out.println("------DoubleToIntFunction------");
int x1= 8;
DoubleToIntFunction doubleToIntFunction = (qy)->{
return (int)(qy*x1);
};
System.out.println("doubleToIntFunction>>>"+doubleToIntFunction.applyAsInt(8.95));
System.out.println("------DoubleToIntFunction------");
}
輸出內容爲:
------DoubleToIntFunction------
doubleToIntFunction>>>71
------DoubleToIntFunction------
DoubleToLongFunction:
接受一個double類型輸入,返回一個long類型結果
public static void main(String[] args) {
System.out.println("------DoubleToLongFunction------");
long x2= 8;
DoubleToLongFunction doubleToLongFunction = (qy)->{
return (long) qy*x2;
};
System.out.println("DoubleToLongFunction>>>"+doubleToLongFunction.applyAsLong(9.5858));
System.out.println("------DoubleToLongFunction------");
}
輸出內容爲:
------DoubleToLongFunction------
DoubleToLongFunction>>>72
------DoubleToLongFunction------
DoubleUnaryOperator:
接受一個參數同爲類型double,返回值類型也爲double 。注意,這種類似的andThen方法,是先將andThen裏面的參數做applyAsDouble操作,然後把結果在做爲參數傳給最外面的那個doubleUnaryOperator做applyAsDouble方法。
public static void main(String[] args) {
System.out.println("------DoubleUnaryOperator------");
DoubleUnaryOperator doubleUnaryOperator = (qu)->qu*2;
DoubleUnaryOperator doubleUnaryOperator1 = (qu)->qu+2;
System.out.println("DoubleUnaryOperator applyAsLong >>>"+doubleUnaryOperator.applyAsDouble(9.00));
System.out.println("DoubleUnaryOperator compose >>>"+doubleUnaryOperator.compose(doubleUnaryOperator1).applyAsDouble(18.0));
System.out.println("DoubleUnaryOperator andThen >>>"+doubleUnaryOperator.andThen(doubleUnaryOperator).applyAsDouble(16.0));
System.out.println("------DoubleUnaryOperator------");
}
輸出內容爲:
------DoubleUnaryOperator------
DoubleUnaryOperator applyAsLong >>>18.0
DoubleUnaryOperator compose >>>40.0
DoubleUnaryOperator andThen >>>64.0
------DoubleUnaryOperator------
Function:
接受一個輸入參數,返回一個結果。
public static void main(String[] args) {
System.out.println("------Function------");
Function<String,String> stringFunction = qi->qi+" Hello Word";
Function<String,String> stringFunction1 = qo->qo+" How Are You?";
System.out.println("Function >>>>>>"+stringFunction.apply("JACK"));
System.out.println("Function andThen>>>>>>"+stringFunction.andThen(stringFunction1).apply("Tom"));
System.out.println("Function compose>>>>>>"+stringFunction.compose(stringFunction1).apply("Tony"));
System.out.println("------Function------");
}
輸出內容爲:
------Function------
Function >>>>>>JACK Hello Word
Function andThen>>>>>>Tom Hello Word How Are You?
Function compose>>>>>>Tony How Are You? Hello Word
------Function------
IntBinaryOperator:
接受兩個參數同爲類型int,返回值類型也爲int 。
public static void main(String[] args) {
System.out.println("------IntBinaryOperator------");
IntBinaryOperator binaryOperator1=(qp,qa)->{
if (qp>qa){
return qp-qa;
}else {
return qa-qp;
}
};
System.out.println("IntBinaryOperator >>>>>>"+binaryOperator1.applyAsInt(8,5));
System.out.println("IntBinaryOperator >>>>>>"+binaryOperator1.applyAsInt(1,5));
System.out.println("------IntBinaryOperator------");
}
輸出內容爲:
------IntBinaryOperator------
IntBinaryOperator >>>>>>3
IntBinaryOperator >>>>>>4
------IntBinaryOperator------
IntConsumer:
接受一個int類型的輸入參數,無返回值 。
public static void main(String[] args) {
System.out.println("------IntConsumer------");
IntConsumer intConsumer = qs->{
System.out.println(qs*100000);
};
IntConsumer intConsumer1 = qd->{
System.out.println(">>>>>"+qd*15);
};
intConsumer.accept(789);
intConsumer1.andThen(intConsumer).accept(8);
System.out.println("------IntConsumer------");
}
輸出內容爲:
------IntConsumer------
78900000
>>>>>120
800000
------IntConsumer------
** IntFunction:**
接受一個int類型輸入參數,返回一個結果(類型不限)
public static void main(String[] args) {
System.out.println("------IntFunction------");
IntFunction<Double> intFunction = qf->{
return x*0.88;
};
System.out.println("IntFunction >>>>>"+intFunction.apply(5));
System.out.println("------IntFunction------");
}
輸出內容爲:
------IntFunction------
IntFunction >>>>>1.76
------IntFunction------
IntPredicate:
接受一個int輸入參數,返回一個布爾值的結果。
public static void main(String[] args) {
System.out.println("------IntPredicate------");
IntPredicate intPredicate = qg->{
return qg>100;
};
IntPredicate intPredicate1 = qh->{
return qh<100;
};
System.out.println("IntPredicate Test>>>>"+intPredicate.test(99));
System.out.println("IntPredicate Test>>>>"+intPredicate.test(150));
System.out.println("IntPredicate negate>>>>"+intPredicate.negate().test(150));
System.out.println("IntPredicate and>>>>"+intPredicate.and(intPredicate1).test(150));
System.out.println("IntPredicate or>>>>"+intPredicate.or(intPredicate1).test(150));
System.out.println("------IntPredicate------");
}
輸出內容爲:
------IntPredicate------
IntPredicate Test>>>>false
IntPredicate Test>>>>true
IntPredicate negate>>>>false
IntPredicate and>>>>false
IntPredicate or>>>>true
------IntPredicate------
IntSupplier:
無參數,返回一個int類型結果
public static void main(String[] args) {
System.out.println("------IntSupplier------");
IntSupplier intSupplier = ()->{
double str = 11.0;
return (int)str;
};
System.out.println("IntSupplier >>>>"+intSupplier.getAsInt());
System.out.println("------IntSupplier------");
}
輸出內容爲:
------IntSupplier------
IntSupplier >>>>11
------IntSupplier------
IntToDoubleFunction:
接受一個int類型輸入,返回一個double類型結果 。
public static void main(String[] args) {
System.out.println("------IntToDoubleFunction------");
IntToDoubleFunction intToDoubleFunction = qj->{
return qj*0.05;
};
System.out.println("intToDoubleFunction >>>>"+intToDoubleFunction.applyAsDouble(19));
System.out.println("------IntToDoubleFunction------");
}
輸出內容爲:
------IntToDoubleFunction------
intToDoubleFunction >>>>0.9500000000000001
------IntToDoubleFunction------
IntToLongFunction:
IntToLongFunction接受一個int類型輸入,返回一個long類型結果。
public static void main(String[] args) {
System.out.println("------IntToLongFunction------");
IntToLongFunction intToLongFunction = qk->{
long ll = (long)2.501 ;
return qk*ll;
};
System.out.println("IntToLongFunction >>>>"+intToLongFunction.applyAsLong(182));
System.out.println("------IntToLongFunction------");
}
輸出內容爲:
------IntToLongFunction------
IntToLongFunction >>>>364
------IntToLongFunction------
IntUnaryOperator:
接受一個參數同爲類型int,返回值類型也爲int 。
public static void main(String[] args) {
System.out.println("------IntUnaryOperator------");
IntUnaryOperator intUnaryOperator = ql->{
return ql *100;
};
IntUnaryOperator intUnaryOperator1 = qz->{
return qz *500;
};
System.out.println("IntToLongFunction >>>>"+intUnaryOperator.applyAsInt(52));
System.out.println("IntToLongFunction >>>>"+intUnaryOperator1.applyAsInt(52));
System.out.println("IntToLongFunction andThen >>>>"+intUnaryOperator.andThen(intUnaryOperator1).applyAsInt(52));
System.out.println("IntToLongFunction compose >>>>"+intUnaryOperator.compose(intUnaryOperator1).applyAsInt(52));
System.out.println("------IntUnaryOperator------");
}
輸出內容爲:
------IntUnaryOperator------
IntToLongFunction >>>>5200
IntToLongFunction >>>>26000
IntToLongFunction andThen >>>>2600000
IntToLongFunction compose >>>>2600000
------IntUnaryOperator------
LongBinaryOperator:
接受兩個參數同爲類型long,返回值類型也爲long。
public static void main(String[] args) {
System.out.println("------LongBinaryOperator------");
LongBinaryOperator longBinaryOperator = (qx,qc)->{
if (qx>qc){
return qx - qc;
}else{
return qx*qc;
}
};
System.out.println("LongBinaryOperator >>>>"+longBinaryOperator.applyAsLong(18,9));
System.out.println("LongBinaryOperator >>>>"+longBinaryOperator.applyAsLong(80,90));
System.out.println("------LongBinaryOperator------");
}
輸出內容爲:
------LongBinaryOperator------
LongBinaryOperator >>>>9
LongBinaryOperator >>>>7200
------LongBinaryOperator------
LongConsumer:
接受一個long類型的輸入參數,無返回值。
public static void main(String[] args) {
System.out.println("------LongConsumer------");
LongConsumer longConsumer = (qv)-> System.out.println(">>>>>>>"+qv);
LongConsumer longConsumer1 = (qb)-> System.out.println("<<<<<<"+qb);
longConsumer.accept(8);
longConsumer1.andThen(longConsumer).accept(999);
System.out.println("------LongConsumer------");
}
輸出內容爲:
------LongConsumer------
>>>>>>>8
<<<<<<999
>>>>>>>999
------LongConsumer------
LongFunction:
接受一個long類型輸入參數,返回一個結果。
public static void main(String[] args) {
System.out.println("------LongFunction------");
LongFunction longFunction = qn->{
return String.valueOf(qn);
};
System.out.println("LongFunction >>>>"+ longFunction.apply(12333333));
System.out.println("LongFunction type>>>>"+ (longFunction.apply(12333333)).getClass().toString());
System.out.println("------LongFunction------");
}
輸出內容爲:
------LongFunction------
LongFunction >>>>12333333
LongFunction type>>>>class java.lang.String
------LongFunction------
LongPredicate:
R接受一個long輸入參數,返回一個布爾值類型結果。
public static void main(String[] args) {
System.out.println("------LongPredicate------");
LongPredicate longPredicate = qm->{
if(qm>100){
return true;
}else{
return false;
}
};
LongPredicate longPredicate1 = wq->{
if(wq<100){
return true;
}else{
return false;
}
};
System.out.println("LongPredicate >>>>"+ longPredicate.test(10000000));
System.out.println("LongPredicate >>>>"+ longPredicate.test(10));
System.out.println("LongPredicate >>>>"+ longPredicate.negate().test(10));
System.out.println("LongPredicate and >>>>"+ longPredicate.and(longPredicate).test(100));
System.out.println("LongPredicate or >>>>"+ longPredicate.or(longPredicate).test(100));
System.out.println("------LongPredicate------");
}
輸出內容爲:
------LongPredicate------
LongPredicate >>>>true
LongPredicate >>>>false
LongPredicate >>>>true
LongPredicate and >>>>false
LongPredicate or >>>>false
------LongPredicate------
LongSupplier:
無參數,返回一個結果long類型的值。
public static void main(String[] args) {
System.out.println("------LongSupplier------");
LongSupplier longSupplier = ()->{
return Long.valueOf("111111");
};
System.out.println("LongSupplier >>>>"+ longSupplier.getAsLong());
System.out.println("------LongSupplier------");
}
輸出內容爲:
------LongSupplier------
LongSupplier >>>>111111
------LongSupplier------
LongToDoubleFunction:
接受一個long類型輸入,返回一個double類型結果。
public static void main(String[] args) {
System.out.println("------LongToDoubleFunction------");
LongToDoubleFunction longToDoubleFunction = (ww)->{
return Double.valueOf(ww);
};
System.out.println("longToDoubleFunction >>>>"+ longToDoubleFunction.applyAsDouble(1000000));
System.out.println("------LongToDoubleFunction------");
}
輸出內容爲:
------LongToDoubleFunction------
longToDoubleFunction >>>>1000000.0
------LongToDoubleFunction------
LongToIntFunction:
接受一個long類型輸入,返回一個int類型結果。
public static void main(String[] args) {
System.out.println("------LongToIntFunction------");
LongToIntFunction longToIntFunction = (wr)->{
return (int)wr;
};
System.out.println("longToDoubleFunction >>>>"+ longToIntFunction.applyAsInt(9999999));
System.out.println("------LongToIntFunction------");
}
輸出內容爲:
------LongToIntFunction------
longToDoubleFunction >>>>9999999
------LongToIntFunction------