本文整理匯總了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();
}