Q:

Java ArrayList clear() method

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

A:

You're using raw ArrayList, thus you can store any kind of Object in your lists. Note that you're storing al inside alal, which means storing the reference of al into alal, not the values from al into alal.
More in depth explanation:
al.add(Str1); //al -> [String 1]
alal.add(al); //alal -> [ [String 1] ]

al.clear(); //al -> []   ,   alal -> [ [] ]
al.add(Str2); // al -> [String 2] , alal -> [ [String 2] ]
alal.add(Str3); //alal -> [ [String 2], String 3]

System.out.println(al);
System.out.println(alal);

Some advices from your given code:

Use better names for your variables. al and alal may look good for a basic example, but it would be better providing names that help to the code readability.
If you want to prevent you or another programmer to store anything in an ArraList (or in another Collection), use generics. This mean, declare the variable like ArrayList<String> alal so now the compiler will check that you can add String values only.
If you wanted to pass the elements from al to alal, use ArrayList#addAll method.
In this case, it would be better declaring the variables as List instead to ArrayList. It is better to get used to program to an interface rather than a direct class implementation:

