0

是否有等效于从位图中获取所有键(或逆)并将每个键与特殊字符连接为全新字符串的方法(无需遍历映射并手动构建它?

private static final BiMap<String, String> stuff = HashBiMap.create();
static {
    stuff.put("S1", "STUFF_TYPE_1");
    stuff.put("S2", "STUFF_TYPE_2");
    stuff.put("S3", "STUFF_TYPE_3");
} 

// The non-terminal <> is what I'm asking if something like exists either with bimap or some other container?
private static final String concateKeys = <stuff.getAllKeys().assignDelimiter("|").toString();>

然后 concateKeys 的值 = "S1|S2|S3"

4

2 回答 2

1

也许你想看看Google Guava libraryJoiner的类。

于 2014-01-22T08:04:30.837 回答
1

假设这是番石榴BiMap,这只是

Joiner.on('|').join(stuff.keySet());
于 2014-01-22T17:01:43.617 回答