BiMap单一函数将值转换为串联字符串值?

时间:2014-01-22 07:58:21

标签: java map bimap

是否有相当于从位图中获取所有键(或反转)的东西,并将每个特殊字符作为一个全新的字符串连接(不迭代地图并手动构建它?

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”

2 个答案:

答案 0 :(得分:1)

也许你想看一下Google Guava libraryJoiner类。

答案 1 :(得分:1)

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

Joiner.on('|').join(stuff.keySet());