How do you create an ArrayList with one element in Java?

You can use the utility method Arrays. asList and feed that result into a new ArrayList . List<String> list = new ArrayList<String>(Collections. singletonList(s));

Sizin İçin Seçtik  How do you call a method using an array of objects in Java?

Leave a Reply

Your email address will not be published. Required fields are marked *