forked from FatimaAlazazi/DataStructure2021
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPair.java
More file actions
46 lines (38 loc) · 1.07 KB
/
Pair.java
File metadata and controls
46 lines (38 loc) · 1.07 KB
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
36
37
38
39
40
41
42
43
44
45
46
package Week4;
public class Pair<A,B> {
A first;
B second;
public Pair(A first, B second) {
this.first = first;
this.second = second;
}
public A getFirst() {
return first;
}
public void setFirst(A first) {
this.first = first;
}
public B getSecond() {
return second;
}
public void setSecond(B second) {
this.second = second;
}
@Override
public String toString() {
return "Pair{" +
"first=" + first +
", second=" + second +
'}';
}
public static void main(String[] args) {
Pair<String,Integer> bookPair =new Pair<>("book1",22); // the Name of Class not Int Integer.
String x=bookPair.getFirst();
int y=bookPair.getSecond();
System.out.println(x+" "+y);
Student s1=new Student("khaled",30,122);
Student s2=new Student("jalal",45,114);
Pair <Student,Student> comp =new Pair<> (s1,s2);
System.out.println(comp);
}
}