Skip to content

Codes #278

@siddharthrgade21-a11y

Description

@siddharthrgade21-a11y

import java.util.;
import java.util.concurrent.
;
import java.util.stream.Collectors;

public class AdvancedDataProcessor {

public static void main(String[] args) {
    // Sample list of strings, including some null and empty values
    List<String> rawData = Arrays.asList("Java", "Advanced", null, "Concurrency", "", "Streams", "Optional");

    // Using CompletableFuture for asynchronous execution
    CompletableFuture.supplyAsync(() -> processData(rawData))
        .thenAccept(result -> {
            System.out.println("Processing Complete!");
            result.forEach(System.out::println);
        })
        .exceptionally(ex -> {
            System.err.println("Error occurred: " + ex.getMessage());
            return null;
        })
        .join(); // Wait for completion (for demo purposes)
}

/**
 * Processes a list of strings: filters out nulls/empties, 
 * converts to uppercase, and sorts alphabetically.
 */
public static List<String> processData(List<String> data) {
    return Optional.ofNullable(data)
        .orElseGet(Collections::emptyList)
        .stream()
        // Filter: Remove nulls and empty strings
        .filter(str -> str != null && !str.isBlank())
        // Map: Transform to uppercase
        .map(String::toUpperCase)
        // Sort: Natural alphabetical order
        .sorted()
        // Collect into a new List
        .collect(Collectors.toList());
}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions