import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.stream.Collectors;

// The main method must be in a class named "Main".
class Main {
    public static void main(String[] args) {
        System.out.println(concatenateWithSpace("123 ", null, "  asd", "  "));
    }

    public static String concatenateWithSpace(String ...strings) {
        if (strings == null) return "";
        return Arrays.stream(strings)
                .filter(string -> string != null && string.trim().length() > 0)
                .map(String::trim)
                .collect(Collectors.joining(" "));
    }
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: