StringJoiner setEmptyValue() 方法在 Java 8 中
Java 8 中 StringJoiner 类 的 setEmptyValue() 方法设置字符序列。这些字符用于确定此 StringJoiner 的字符串表达式以及何时为空。这表示尚未添加任何元素。
语法如下
public StringJoiner setEmptyValue(CharSequence emptyVal)
其中, emptyVal 为一个空 StringJoiner 的值返回的字符
要使用 Java 8 中的 StringJoiner,请导入以下包。
import java.util.StringJoiner;
以下是一个在 Java 中实现 StringJoiner setEmptyValue() 方法的示例
示例
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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP