I have a LinkedHashMap where CommonEnum represents a type of byte[] that I want to keep track of.
LinkedHashMap<CommonEnum, byte[]> map = new LinkedHashMap<CommonEnum, byte[]>();
What is the most efficient way in Java to flatten this into a continuous
byte[]
with the same ordering (thats why the HashMap is Linked).
If you can use a
LinkedHashMap<CommonEnum, byte[]>, it gets easier, and I have no idea why you would useByte[], so I assume this.I’m not sure about most efficient, but these two would be what I think about:
System.arraycopyfor each.Arrays.copyOfto shorten it.By the way, if your CommonEnum values are always of the same order (and you can use this order as the order in the enum definition), you can use an
EnumMapinstead.