Question

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"

Was it helpful?

Solution

Assuming this is a Guava BiMap, this is just

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

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top