there is a large array of type String s[ ]={"a", "b", "c", "d"}; but I need to do in ArrayList< String > as so that elements can be deleted. The copying method from String s[ ] to ArrayList not suitable, you need to immediately enter it, and enter it with the method as.add("a") , etc. very uncomfortable. How to enter all elements in one line? those. is it possible as in String s[ ]={"a", "b", "c", "d"};

    1 answer 1

    Can. You need the Arrays.asList(...) method, which is a popular way to create a list of previously known elements.

     List<String> as = Arrays.asList("a", "b", "c", "d"); 

    But there is one thing. The resulting list will not be a real ArrayList . In general, it will not hurt you if you do not want, for example, to serialize this list.

    An “honest” ArrayList can be obtained by wrapping the list in a constructor:

      List<String> as = new ArrayList(Arrays.asList("a", "b", "c", "d")); 
    • Thank you so much, I will try! - Hellraiser