I can't really understand the code below. The clear method removes all elements assigned to "al" right? Then the ArrayList al receives the value of string Str2 and alal receives the value of Str3.
So how on earth the output is as below if alal is assigned only with Str3? Could someone kindly explain? Many thanks
OUTPUT:
[String 2]
[[String 2], String 3]
public static void main(String[] args){
String Str1 = "String 1";
String Str2 = "String 2";
String Str3 = "String 3";
ArrayList al = new ArrayList();
ArrayList alal = new ArrayList();
al.add(Str1);
alal.add(al);
al.clear();
al.add(Str2);
alal.add(Str3);
System.out.println(al);
System.out.println(alal);
}