当前位置: 首页>>代码示例>>Java>>正文


Java StringJoiner.merge方法代码示例

本文整理汇总了Java中java.util.StringJoiner.merge方法的典型用法代码示例。如果您正苦于以下问题:Java StringJoiner.merge方法的具体用法?Java StringJoiner.merge怎么用?Java StringJoiner.merge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.StringJoiner的用法示例。


在下文中一共展示了StringJoiner.merge方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:17,代码来源:MergeTest.java

示例2: testNull

import java.util.StringJoiner; //导入方法依赖的package包/类
public void testNull() {
    StringJoiner sj = new StringJoiner(",", "{", "}");
    try {
        sj.merge(null);
        fail("Should throw NullPointerException!");
    } catch (NullPointerException npe) {
        // expected
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:10,代码来源:MergeTest.java

示例3: testSimple

import java.util.StringJoiner; //导入方法依赖的package包/类
public void testSimple() {
    StringJoiner sj = new StringJoiner(",", "{", "}");
    StringJoiner other = new StringJoiner(",", "[", "]");
    Stream.of("a", "b", "c").forEachOrdered(sj::add);
    Stream.of("d", "e", "f").forEachOrdered(other::add);

    sj.merge(other);
    assertEquals(sj.toString(), "{a,b,c,d,e,f}");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:10,代码来源:MergeTest.java

示例4: 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}");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:13,代码来源:MergeTest.java

示例5: testEmptyThis

import java.util.StringJoiner; //导入方法依赖的package包/类
public void testEmptyThis() {
    StringJoiner sj = new StringJoiner(",", "{", "}");
    StringJoiner other = new StringJoiner(":", "[", "]");
    Stream.of("d", "e", "f").forEachOrdered(other::add);

    sj.merge(other);
    assertEquals(sj.toString(), "{d:e:f}");

    sj = new StringJoiner(",", "{", "}").setEmptyValue("EMPTY");
    assertEquals(sj.toString(), "EMPTY");
    sj.merge(other);
    assertEquals(sj.toString(), "{d:e:f}");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:14,代码来源:MergeTest.java

示例6: testCascadeEmpty

import java.util.StringJoiner; //导入方法依赖的package包/类
public void testCascadeEmpty() {
    StringJoiner sj = new StringJoiner(",", "{", "}");
    StringJoiner o1 = new StringJoiner(":", "[", "]").setEmptyValue("Empty1");
    StringJoiner o2 = new StringJoiner(",", "<", ">").setEmptyValue("Empty2");

    o1.merge(o2);
    assertEquals(o1.toString(), "Empty1");

    sj.merge(o1);
    assertEquals(sj.toString(), "{}");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:12,代码来源:MergeTest.java

示例7: testDelimiter

import java.util.StringJoiner; //导入方法依赖的package包/类
public void testDelimiter() {
    StringJoiner sj = new StringJoiner(",", "{", "}");
    StringJoiner other = new StringJoiner(":", "[", "]");
    Stream.of("a", "b", "c").forEachOrdered(sj::add);
    Stream.of("d", "e", "f").forEachOrdered(other::add);

    sj.merge(other);
    assertEquals(sj.toString(), "{a,b,c,d:e:f}");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:10,代码来源:MergeTest.java

示例8: testNull

import java.util.StringJoiner; //导入方法依赖的package包/类
@Test(expectedExceptions = {NullPointerException.class})
public void testNull() {
    StringJoiner sj = new StringJoiner(",", "{", "}");
    sj.merge(null);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:6,代码来源:MergeTest.java


注:本文中的java.util.StringJoiner.merge方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。