Aruna Balasuriya wrote:....
Though the type of ArrayList mark as String it accepts Integers.How ?
Hi Aruna, Welcome to JavaRanch
Though it compiles you get an unchecked warning as the compiler looks at the reference type which is of List (raw type) hence not able to do the type checking.
You have used List x = new ArrayList<String>(); which means the list x can accept element of any datatype. If you specifically want to add elements of string type then you have to modify it as: