fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. List<Integer> list= new LinkedList<>();
  13. list.add(5);
  14. list.add(2);
  15. list.add(5);
  16.  
  17. reomveDuplicates(list);
  18. }
  19.  
  20. public static void reomveDuplicates(List<Integer> list) {
  21. LinkedHashSet<Integer> setWithoutDuplicates = new LinkedHashSet<Integer>();
  22. for(Integer elem: list) {
  23. setWithoutDuplicates.add(elem);
  24. }
  25. list.clear();
  26.  
  27. for(Integer elem: setWithoutDuplicates) {
  28. list.add(elem);
  29. }
  30. }
  31. }
Success #stdin #stdout 0.04s 711168KB
stdin
Standard input is empty
stdout
Standard output is empty