import java.util.Scanner; import java.util.function.Function; public class LambdaStringCase { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter a string: "); String input = scanner.nextLine(); Function<String, String> toUpperCase = str -> str.toUpperCase(); Function<String, String> toLowerCase = str -> str.toLowerCase(); String upperCaseString = toUpperCase.apply(input); System.out.println("Uppercase: " + upperCaseString); String lowerCaseString = toLowerCase.apply(input); System.out.println("Lowercase: " + lowerCaseString); } }
Preview:
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