Could someone explain the meaning of the following code, especially ArrayList and List and why do we need to use both?
String [] forecastArray =
{
"Today - Sunny - 35/30",
"Tomorrow - Foggy - 33/28",
"Wednesday - Cloudy - 33/26",
"Thursday - Sleepy - 30/24",
"Friday - Bunking - 36/34",
"Saturday - Trapped - 38/35",
"Sunday - Heavy Rain - 32/28"
};
List<String> myList = Arrays.asList(forecastArray);
List<String> weekForecast = new ArrayList<>(myList);
myListis aListbacked by theforecastArrayand is immuteable. You won't be able to change it.weekForecastis backed by a copy of that array and can be changed.