Convert Array to List using asList(...)

Considering you have an array of String, the following code bit transforms it into a List.

String[] array = new String[] {"Cat", "Dog", "Bird"};
List<String> list = Arrays.asList(array);


Converting data structures between arrays and lists (and vice-versa), is a standard programming activity. Java provides some options for doing this, but when it comes to converting an array to a list, the current best option is to use the bridge method Arrays.asList(...). Additionally, this method is useful to create in-line lists, without requiring to instantiate a list and the method add or similar to insert elements into this list.

Check other articles for more information and quick code bits for performing your programming activities.