In figure below, if switch S is open then total energy stored in the capacitors, is suppose E0
Energy in IF capacitor, E1=21CV2=21C(CQ)2 =21CQ2=21×142=8J
Similarly, E2=21CQ2=2×222=1J
So, the total energy, E0=E1+E2=8+l=9J
Now, switch's is closed then the common potential of Capacitors, Vcommon =C1+C2C1V1+C2V2 =1+21×4+2×1=36=2V
Hence, now the new arrangement of energy, E1=21C1Vcommon 2=21×1×4=2J
and E2=21C2Vcommon 2=21×2×4=4J
Now, from conservation of energy,
Energy stored in the inductor, EL≃E0−(E1+E2) =9−(2+4)=3J
Hence, the inductor has 3J of energy.