Code Logo

Transform Strings Using References

Published at13 Jan 2026
Medium 20 views
Like17

You are given a list of strings and need to return a new list where each string has been converted to uppercase.

This problem is about doing that transformation with Java method references. The input is not a single string. It is a whole collection of strings, and each item in that collection should be processed the same way.

For example, ["hello", "world", "java"] should become ["HELLO", "WORLD", "JAVA"]. If the list is empty, the answer stays empty. Strings that do not contain lowercase letters, like "123" or "C++", naturally stay the same when uppercase is applied.

So the task is to transform every string in the list to uppercase and return the transformed list.

Example Input & Output

Example 1
Input
strings = ["hello", "world", "java"]
Output
["HELLO", "WORLD", "JAVA"]
Explanation

Each string in the list is transformed to uppercase.

Example 2
Input
strings = []
Output
[]
Explanation

An empty input list stays empty after transformation.

Example 3
Input
strings = ["Python", "Java", "C++"]
Output
["PYTHON", "JAVA", "C++"]
Explanation

Alphabetic text becomes uppercase, while symbols like plus signs stay unchanged.

Algorithm Flow

Recommendation Algorithm Flow for Transform Strings Using References
Recommendation Algorithm Flow for Transform Strings Using References

Solution Approach

The main Java concept here is using a stream method reference instead of a longer lambda when the operation already exists as a named method. Since every string should be converted to uppercase, the stream pipeline does not need filtering or special branching. It just needs to map each input string to its uppercase version and collect the results.

A clean Java solution is:

return strings.stream().map(String::toUpperCase).collect(Collectors.toList());

The map step means "transform each element into a new element." The method reference String::toUpperCase is a compact way to say that every string should call its own toUpperCase() method. It is functionally similar to writing s -> s.toUpperCase(), but method references are often clearer when the operation is simple and direct.

After mapping, collect(Collectors.toList()) gathers the transformed values into a new list in the same encounter order. That is important because the output should preserve the order of the input list.

This solution runs in O(n) time with respect to the number of strings, aside from the character work inside each uppercase conversion. More importantly, it expresses the intent very clearly: take each string, apply one standard transformation, and return the transformed list.

Best Answers

java - Approach 1
import java.util.List;
import java.util.stream.Collectors;

class Solution {
    public List<String> transformStrings(List<String> strings) {
        return strings.stream()
                     .map(String::toUpperCase)
                     .collect(Collectors.toList());
    }
}