Wednesday, October 10, 2012

How to declare a List by initializing a value

Just curious to share this info, Many times we might have a requirement to pass a List as a input parameter , Instead of declaring variable, and adding elements one by one to the list, The below tip may allows you to directly pass List without creating a variable and add the elements.


getEmployeeDetails(Arrays.asList("123","456",222"));

Arrays.asList() - will return a java.util.List

No comments:

Post a Comment