Converting String array to java.util.List

前端 未结 6 1835
孤街浪徒
孤街浪徒 2020-12-07 11:30

How do I convert a String array to a java.util.List?

6条回答
  •  一个人的身影
    2020-12-07 12:18

    First Step you need to create a list instance through Arrays.asList();

    String[] args = new String[]{"one","two","three"};
    List list = Arrays.asList(args);//it converts to immutable list
    

    Then you need to pass 'list' instance to new ArrayList();

    List newList=new ArrayList<>(list);
    

提交回复
热议问题