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

    public static void main(String[] args) {
        // Lambda expression to reverse a string
        StringReverser reverser = (str) -> new StringBuilder(str).reverse().toString();
        
        String example = "Hello, World!";
        String reversed = reverser.reverse(example);
        
        // Print original and reversed strings
        System.out.println("Original: " + example);
        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