adding char array to HashSet
I have a HashSet of Character and I am trying to do:
Collections.addAll(mySet, test.toCharArray());
myS开发者_StackOverflowet.addAll(test.toCharArray());
why is it saying it is not applicable? How do I fix this?
Because toCharArray()
yields a char[]
, not a Character[]
. Java generics don't work with primitives, so I guess you need to add each element manually.
I just stumbled upon another open source library that provides a high performance collections for primitives -- HPPC http://labs.carrotsearch.com/hppc.html
They were motivated by performance issues on autoboxing, and well, having primitives directly supported in collections.
Looks pretty good.
精彩评论