Preview:
@FunctionalInterface
interface StringReverser {
    String reverse(String str);
}

public class StringReverseLambda {
    public static void main(String[] args) {
        // Lambda expression to reverse a string
        StringReverser reverser = (str) -> new StringBuilder(str).reverse().toString();

        // Example string
        String input = "Hello, World!";
        
        // Reverse the string and print the result
        String reversed = reverser.reverse(input);
        System.out.println("Original: " + input);
        System.out.println("Reversed: " + reversed);
    }
}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter