Online Java Compiler By
JavaTpoint.com
import java.util.*; public class CollectionsCheckedCollectionExample3 { public static void main(String[] args) { Collection
c = new ArrayList<>(); c = Collections.checkedCollection(c, String.class); Collections.addAll(c, "apple", "banana"); System.out.println(c); @SuppressWarnings("rawtypes") Collection c2 = c; c2.add(1);//this throws exception System.out.println(c2); } }
Output