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

Comments

Popular posts from this blog

How to set Java Object into JaxBElement ?

GitLab