fork download
  1. import java.util.*;
  2.  
  3. class Example {
  4. public static void main(String[] args) {
  5. List<String> list = new ArrayList<>();
  6. list.add("Abc");
  7.  
  8. Collection<?> c = list;
  9. addSelf(c);
  10. System.out.println(c);
  11. }
  12.  
  13. static <T> void addSelf(Collection<T> c) {
  14. c.addAll(new ArrayList<>(c));
  15. }
  16. }
Success #stdin #stdout 0.06s 2184192KB
stdin
Standard input is empty
stdout
[Abc, Abc]