Need for new String[0] in the Set toArray() method

后端 未结 2 455
暖寄归人
暖寄归人 2020-12-18 10:00

I am trying to convert a Set to an Array.

Set s = new HashSet(Arrays.asList(\"mango\",\"guava\",\"apple\"));
String[] a = s.toArr         


        
2条回答
  •  猫巷女王i
    2020-12-18 10:14

    The parameter is a result of one of the many well-known limitations in the Java generics system. Basically, the parameter is needed in order to be able to return an array of the correct type.

提交回复
热议问题