Guest User

Untitled

a guest
Oct 2nd, 2021
63
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.ArrayList;
  2. import java.util.List;
  3. import java.util.Scanner;
  4. import java.util.stream.Collectors;
  5.  
  6. public class Remove_Duplicates {
  7. public static void main(String[] args) {
  8. Scanner scanner = new Scanner(System.in);
  9.  
  10. String[] input = scanner.nextLine().split(",");
  11. List<Integer> listnums = new ArrayList<>();
  12.  
  13. for (int i = 0; i < input.length; i++) {
  14. listnums.add(Integer.parseInt(input[i]));
  15. }
  16.  
  17. List<Integer> removeDuplicates = listnums.stream().distinct().collect(Collectors.toList());
  18.  
  19. for (int i = 0; i < removeDuplicates.size() - 1; i++) {
  20. System.out.print(removeDuplicates.get(i) + ",");
  21. }
  22. System.out.print(removeDuplicates.get(removeDuplicates.size() - 1));
  23.  
  24.  
  25. }
  26. }
  27.  
RAW Paste Data