You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
770 B
29 lines
770 B
package w8;
|
|
|
|
public class Pair<k,v> {
|
|
private k key;
|
|
private v value;
|
|
public Pair(k key,v value){
|
|
this.key=key;
|
|
this.value=value;
|
|
}
|
|
public k getkey(){
|
|
return key;
|
|
}
|
|
public v getvalue(){
|
|
return value;
|
|
}
|
|
public static <k,v> Pair<v,k> swap(Pair<k,v> pair){
|
|
return new Pair<>(pair.getvalue(),pair.getkey());
|
|
}
|
|
}
|
|
class PairTest {
|
|
public static void main(String[] args) {
|
|
Pair<Integer,String> pair=new Pair<>(1,"a");
|
|
System.out.println(pair.getkey());
|
|
System.out.println(pair.getvalue());
|
|
Pair<String,Integer> pair2=Pair.swap(pair);
|
|
System.out.println(pair2.getkey());
|
|
System.out.println(pair2.getvalue());
|
|
}
|
|
}
|
|
|