017-006-008
Function Composition and Method References
Hard
Problem Description
Function Composition and method References
In this problem, you will create a program that chains three static method references (trim, toUpperCase, addBrackets) of type Function<String, String> using andThen() to build a string processing pipeline and displays the result to standard output.
Learning Objective: Understand function composition with Function.andThen() and method references
Overview
Build a string processing pipeline by composing multiple Functions.
Specifications
- Create
StringProcessorclass with these static methods:trim(String s): removes leading/trailing whitespacetoUpperCase(String s): converts to uppercaseaddBrackets(String s): surrounds with "[" and "]"
- In
main, compose three Functions using andThen() - Process " hello " and output the result
Output Format
Processed: [HELLO]
Ready to Try Running Code?
Log in to access the code editor and execute your solutions for this problem.
Don't have an account?
Sign Up