本文整理汇总了Java中java.util.StringJoiner.setEmptyValue方法的典型用法代码示例。如果您正苦于以下问题:Java StringJoiner.setEmptyValue方法的具体用法?Java StringJoiner.setEmptyValue怎么用?Java StringJoiner.setEmptyValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.StringJoiner
的用法示例。
在下文中一共展示了StringJoiner.setEmptyValue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testEmptyBoth
import java.util.StringJoiner; //导入方法依赖的package包/类
public void testEmptyBoth() {
StringJoiner sj = new StringJoiner(",", "{", "}");
StringJoiner other = new StringJoiner(":", "[", "]");
sj.merge(other);
assertEquals(sj.toString(), "{}");
other.setEmptyValue("NOTHING");
sj.merge(other);
assertEquals(sj.toString(), "{}");
sj = new StringJoiner(",", "{", "}").setEmptyValue("EMPTY");
assertEquals(sj.toString(), "EMPTY");
sj.merge(other);
assertEquals(sj.toString(), "EMPTY");
}
示例2: testEmptyOther
import java.util.StringJoiner; //导入方法依赖的package包/类
public void testEmptyOther() {
StringJoiner sj = new StringJoiner(",", "{", "}");
StringJoiner other = new StringJoiner(",", "[", "]");
Stream.of("a", "b", "c").forEachOrdered(sj::add);
sj.merge(other);
assertEquals(sj.toString(), "{a,b,c}");
other.setEmptyValue("EMPTY");
sj.merge(other);
assertEquals(sj.toString(), "{a,b,c}");
}
示例3: toString
import java.util.StringJoiner; //导入方法依赖的package包/类
public String toString() {
StringBuilder sb = new StringBuilder();
if (ownerType != null) {
sb.append(ownerType.getTypeName());
sb.append("$");
if (ownerType instanceof ParameterizedTypeImpl) {
// Find simple name of nested type by removing the
// shared prefix with owner.
sb.append(rawType.getName().replace( ((ParameterizedTypeImpl)ownerType).rawType.getName() + "$",
""));
} else
sb.append(rawType.getSimpleName());
} else
sb.append(rawType.getName());
if (actualTypeArguments != null) {
StringJoiner sj = new StringJoiner(", ", "<", ">");
sj.setEmptyValue("");
for(Type t: actualTypeArguments) {
sj.add(t.getTypeName());
}
sb.append(sj.toString());
}
return sb.toString();
}