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");

);


文章標籤
創作者介紹

經驗交流分享與備忘

Frank 發表在 痞客邦 PIXNET 留言(0) 人氣()