當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。