在 Java 中將 null 連線到字串
若要將 null 連線到字串,請使用 + 運算子。
假設以下內容是我們的字串。
String str = "Demo Text";
現在,我們將瞭解如何輕鬆地將 null 連線到字串。
String strNULL = str + "null";
以下是最終示例。
示例
public class Demo { public static void main(String[] args) { String str = "Demo Text"; System.out.println("String = "+str); String strNULL = str + "null"; System.out.println("String concatenated with NULL: "+strNULL); } }
輸出
String = Demo Text String concatenated with NULL: Demo Textnull
廣告