Just a quick question, how would you go about initializing a new ArrayList in a constructor which takes its values as parameters?
For example say I have a class which has an ArrayList of strings called bookings. I've already written a constructor which sets all fields to default values, so sets bookings to a new ArrayList of strings. However, the task I've been given is to write a second constructor which uses parameters to set the field values instead of setting them to defaults. This is fine for all my other fields, but how would I do this with the ArrayList?
Ans:
ArrayList<String> lstData = new ArrayList<String>(
Arrays.asList("ListItem1","ListItem2","ListItem3","ListItem4");
);
留言列表