3. Write a java program that takes a string as parameter and calculates the reverse of the string using lambda expression.
Sun May 26 2024 20:21:50 GMT+0000 (Coordinated Universal Time)
Saved by
@prabhas
public class ReverseStringLambda {
@FunctionalInterface
interface StringReverser {
String reverse(String str);
}
public static void main(String[] args) {
StringReverser reverser = (str) -> new StringBuilder(str).reverse().toString();
String example = "Hello, World!";
String reversed = reverser.reverse(example);
System.out.println("Original: " + example);
System.out.println("Reversed: " + reversed);
}
}
content_copyCOPY
Comments