I'm fairly out of touch with my Java programming and am doing Google's Udacity course as a refresher. I was going through lesson 1 on the Sunshine app where the lecturer chose to create fake data by declaring an array of strings and then converting it to an ArrayList.
The code is the following:
String[] data = {
"Mon 6/23 - Sunny - 31/17",
"Tue 6/24 - Foggy - 21/8",
"Wed 6/25 - Cloudy - 22/17",
"Thurs 6/26 - Rainy - 18/11",
"Fri 6/27 - Foggy - 21/10",
"Sat 6/28 - TRAPPED IN WEATHERSTATION - 23/18",
"Sun 6/29 - Sunny - 20/7"
};
List<String> weatherForecast = new ArrayList<>(Arrays.asList(data));
I was wondering is there any advantage to using this convertion method? Why not just immediately declare the data as an ArrayList as such:
ArrayList weatherForecast = new ArrayList();
weatherForecast.add("Today - Sunny - 88/63");
weatherForecast.add("Tomorrow - Foggy = 70/46");
weatherForecast.add("Weds - Cloudy - 72/63");
weatherForecast.add("Thurs 6/26 - Rainy - 18/11");
weatherForecast.add("Sat 6/28 - TRAPPED IN WEATHERSTATION - 23/18");
weatherForecast.add("Sun 6/29 - Sunny - 20/7");
Thanks!