Java 8中的StringJoiner setEmptyValue()方法
setEmptyValue()Java8中的StringJoiner类的方法设置字符序列。在确定此StringJoiner的字符串表示形式以及该字符串为空时,将使用这些字符。那将是没有添加任何元素。
语法如下
public StringJoiner setEmptyValue(CharSequence emptyVal)
在这里,emptyVal是作为空StringJoiner的值返回的字符
要在Java8中使用StringJoiner,请导入以下软件包。
import java.util.StringJoiner;
以下是setEmptyValue()在Java中实现StringJoiner方法的示例:
示例
import java.util.StringJoiner;
public class Demo {
public static void main(String[] args) {
StringJoiner strJoiner = new StringJoiner(",");
System.out.println("StringJoiner is empty" + strJoiner);
System.out.println(strJoiner.setEmptyValue("Empty!"));
System.out.println(strJoiner);
System.out.println("After Adding elements to the StringJoiner...");
strJoiner.add("John");
strJoiner.add("Tim");
strJoiner.add("Jacob");
strJoiner.add("Kevin");
strJoiner.add("David");
strJoiner.add("Tom");
System.out.println(strJoiner);
}
}输出结果
StringJoiner is empty Empty! Empty! After Adding elements to the StringJoiner... John,Tim,Jacob,Kevin,David,Tom
热门推荐
10 元宵发客户祝福语简短
11 成年礼简短的祝福语
12 生日祝福语简短霸气男
13 新年祝福语大全简短感谢
14 集体生日祝福语简短的
15 祝贺母校祝福语简短英语
16 生日高考祝福语妹妹简短
17 生日贺卡祝福语简短创意
18 新年简短祝福语给亲人