Which design pattern is represented by the following code?

List<String> strings = Arrays.asList("hello, ", "world", "!");
Explanation
Method Arrays.asList(...) takes array as an argument and returns a List containing elements of that array. The method returns an instance of Arrays.ArrayList and this object adapts the array to the List interface.
Read more: Adapter pattern
This method is also a factory method for List.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes