Java 8 - Primitive type Functional Interface for Supplier
Primitive type Functional Interface for Supplier:
1. IntSupplier
public int getAsInt();
2. LongSupplier
public long getAsLong()
3. DoubleSupplier
public double getAsDouble()
4. BooleanSupplier
public boolean getAsBoolean()
class Test
{
public static void main(String[] args)
{
IntSupplier s=()->(int)(Math.random()*10);
String otp="";
for(int i =0;i<6;i++)
{
otp=otp+s.getAsInt();
}
System.out.println("The 6 digit OTP: "+otp);
}
}
Output: The 6 digit OTP: 035716
1. IntSupplier
public int getAsInt();
2. LongSupplier
public long getAsLong()
3. DoubleSupplier
public double getAsDouble()
4. BooleanSupplier
public boolean getAsBoolean()
class Test
{
public static void main(String[] args)
{
IntSupplier s=()->(int)(Math.random()*10);
String otp="";
for(int i =0;i<6;i++)
{
otp=otp+s.getAsInt();
}
System.out.println("The 6 digit OTP: "+otp);
}
}
Output: The 6 digit OTP: 035716
Comments
Post a Comment