Sign in to devexcode.com with google.com

To continue, google.com will share your name, email address, and profile picture with this site. See this site's privacy policy.

2667. Create Hello World Function

Explanation:

To solve this problem, we need to write a function createHelloWorld that returns a new function. This new function should always return the string "Hello World" regardless of any arguments passed to it.

:

import java.util.function.Supplier;

public class Solution {
    public static Supplier<String> createHelloWorld() {
        return () -> "Hello World";
    }

    public static void main(String[] args) {
        Supplier<String> f = createHelloWorld();
        System.out.println(f.get()); // Output: Hello World
    }
}

Code Editor (Testing phase)

Improve Your Solution

Use the editor below to refine the provided solution. Select a programming language and try the following:

  • Add import statement if required.
  • Optimize the code for better time or space complexity.
  • Add test cases to validate edge cases and common scenarios.
  • Handle error conditions or invalid inputs gracefully.
  • Experiment with alternative approaches to deepen your understanding.

Click "Run Code" to execute your solution and view the output. If errors occur, check the line numbers and debug accordingly. Resize the editor by dragging its bottom edge.