Lambdas Function 8
Lambdas Function 8
Q2. Write a program that sorts a list of strings based on their lengths in
descending order. Define a custom comparator using a lambda expression that
compares strings based on their lengths. Use the custom comparator to sort the
list of strings in descending order of length.
Q4. Create a functional interface Shape with a method double area() and a
default method void printArea(). Implement the interface using lambda
expressions for different shapes. Define the Shape functional interface with an
area method. Implement the interface for shapes like circle, square, and
rectangle using lambda expressions. Use the default method to print the area of
each shape.
Q5. Write a program that reads a list of strings, converts them to uppercase,
filters out the strings starting with a vowel, and then prints the remaining
strings.
Q8. Write a program that creates a thread using a lambda expression as the
Runnable and prints "Hello, CSW2!" from the thread. Define a lambda
expression that implements the Runnable interface and prints "Hello, CSW2!".
Create a thread using the lambda expression and start the thread.
Q10. Write a Java program that takes a LocalDateTime object and formats it to
a custom string format ("yyyy-MM-dd HH:mm:ss"). Define a LocalDateTime
object representing a specific date and time. Use DateTimeFormatter to format
the LocalDateTime object to the desired string format.
Q11. Write a Java program that converts a given date and time in UTC to the
local date and time of a specific time zone (e.g., "America/New_York"). Parse a
string representing a date and time in UTC format. Convert the parsed Instant to
a ZonedDateTime using a specific ZoneId.