-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiterator.java
More file actions
28 lines (26 loc) · 835 Bytes
/
iterator.java
File metadata and controls
28 lines (26 loc) · 835 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;
public class iterator {
public static void main(String[] args) {
ArrayList<String> names = new ArrayList<>();
System.out.println("Enter the names : ");
Scanner scanner = new Scanner(System.in);
String inputNames = scanner.nextLine();
for(String name : inputNames.split(" ")){
names.add(name);
}
HashSet<String> uniqueNames = new HashSet<>();
Iterator<String> it= names.iterator();
while(it.hasNext()){
String name = it.next();
if(uniqueNames.contains(name)){
it.remove();
}else {
uniqueNames.add(name);
}
}
System.out.println(names);
}
}