-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTheSet.java
35 lines (25 loc) · 922 Bytes
/
TheSet.java
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
29
30
31
32
33
34
35
import data.PersonModel;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
public class TheSet {
public static void main(String[] args) {
Set<PersonModel> people = new HashSet<>();
people.add(new PersonModel("Dua Lipa", 28));
people.add(new PersonModel("Selena Gomez", 25));
people.add(new PersonModel("Justin Bieber", 18));
people.add(new PersonModel("Selena Gomez", 25));
//people.remove(new PersonModel("Justin Bieber", 18));
System.out.println(people.size());
people.forEach(System.out::println);
System.out.println();
Iterator<PersonModel> iterator = people.iterator();
while (iterator.hasNext()) {
System.out.println(iterator.next());
}
System.out.println();
for (PersonModel person : people) {
System.out.println(person);
}
}
}