开发者

adding char array to HashSet

开发者 https://www.devze.com 2023-03-14 04:48 出处:网络
I have a HashSet of Character and I am trying to do: Collections.addAll(mySet, test.toCharArray()); myS开发者_StackOverflowet.addAll(test.toCharArray());

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消