문제

Is there something equivalent to get all keys (or inverses) from a bit map and concat each with a special character as a completely new string (without iterating through the map and building it manually?

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();>

Then the Value for concateKeys = "S1|S2|S3"

도움이 되었습니까?

해결책

Assuming this is a Guava BiMap, this is just

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

다른 팁

Maybe you want to take a look at the Joiner class of the Google Guava library.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top