Convert a generic list to an array

前端 未结 13 1313
隐瞒了意图╮
隐瞒了意图╮ 2020-12-05 17:13

I have searched for this, but unfortunately, I don\'t get the correct answer.

class Helper {
    public static  T[] toArray(List list) {
           


        
13条回答
  •  无人及你
    2020-12-05 17:36

    See Guava's Iterables.toArray(list, class).

    Example:

    @Test
    public void arrayTest() {
        List source = Arrays.asList("foo", "bar");
        String[] target = Iterables.toArray(source, String.class);
    }
    

提交回复
热议问题