DEMO_OF_LAMBDA_EXCEPTION
Wed May 29 2024 13:21:43 GMT+0000 (Coordinated Universal Time)
Saved by
@signup
interface ExceptionDemo
{ String compute(String s) throws NullPointerException; }
class DemoOfLambdaException
{ public static void main(String[] args)
{
ExceptionDemo ed = (str) -> {
if(str.length()==0 || str==null)
throw new NullPointerException("No String is available");
else
return "The string "+str+" has "+str.length()+" characters.";
};
java.util.Scanner scan = new java.util.Scanner(System.in);
System.out.println("Enter a String: ");
String s = scan.nextLine();
System.out.println(ed.compute(s));
}
}
content_copyCOPY
Comments